Fix accidental float/double NaN parsing in snbt

This commit is contained in:
Nassim Jahnke 2021-11-02 15:09:40 +01:00
parent 0a19057606
commit 7cc6eb2b66
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 10 additions and 2 deletions

View File

@ -277,10 +277,16 @@ final class TagStringReader {
result = new LongTag(Long.parseLong(builder.toString()));
break;
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;
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;
}
} catch (final NumberFormatException ex) {

View File

@ -17,6 +17,7 @@
*/
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.Test;
@ -42,6 +43,7 @@ public class NBTTagTest {
readString("{id:[I;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((byte) 1, readString("{thisisabyte:true}").get("thisisabyte").getValue());
Assertions.assertEquals((byte) 0, readString("{thisisabyte:false}").get("thisisabyte").getValue());