3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Fix accidental float/double NaN parsing in snbt

Dieser Commit ist enthalten in:
Nassim Jahnke 2021-11-02 15:09:40 +01:00
Ursprung 0a19057606
Commit 7cc6eb2b66
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
2 geänderte Dateien mit 10 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -277,10 +277,16 @@ final class TagStringReader {
result = new LongTag(Long.parseLong(builder.toString())); result = new LongTag(Long.parseLong(builder.toString()));
break; break;
case Tokens.TYPE_FLOAT: case Tokens.TYPE_FLOAT:
result = new FloatTag(Float.parseFloat(builder.toString())); final float floatValue = Float.parseFloat(builder.toString());
if (!Float.isNaN(floatValue)) {
result = new FloatTag(floatValue);
}
break; break;
case Tokens.TYPE_DOUBLE: case Tokens.TYPE_DOUBLE:
result = new DoubleTag(Double.parseDouble(builder.toString())); final double doubleValue = Double.parseDouble(builder.toString());
if (!Double.isNaN(doubleValue)) {
result = new DoubleTag(doubleValue);
}
break; break;
} }
} catch (final NumberFormatException ex) { } catch (final NumberFormatException ex) {

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.common.nbt; package com.viaversion.viaversion.common.nbt;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -42,6 +43,7 @@ public class NBTTagTest {
readString("{id:[I;1,2,3,]}"); readString("{id:[I;1,2,3,]}");
readString("{id:[1,2,3,]}"); readString("{id:[1,2,3,]}");
Assertions.assertEquals("NaNd", readString("{id:NaNd}").get("id").getValue());
Assertions.assertEquals("2147483649", readString("{id:9000b,thisisastring:2147483649}").get("thisisastring").getValue()); Assertions.assertEquals("2147483649", readString("{id:9000b,thisisastring:2147483649}").get("thisisastring").getValue());
Assertions.assertEquals((byte) 1, readString("{thisisabyte:true}").get("thisisabyte").getValue()); Assertions.assertEquals((byte) 1, readString("{thisisabyte:true}").get("thisisabyte").getValue());
Assertions.assertEquals((byte) 0, readString("{thisisabyte:false}").get("thisisabyte").getValue()); Assertions.assertEquals((byte) 0, readString("{thisisabyte:false}").get("thisisabyte").getValue());