From e46803700b750ba312ff0d29212411a8bfacf2b5 Mon Sep 17 00:00:00 2001 From: Revxrsal Date: Sat, 19 Oct 2024 12:21:13 +0300 Subject: [PATCH] disallow NaN, Infinity and -Infinity values --- .../revxrsal/commands/stream/MutableStringStreamImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/revxrsal/commands/stream/MutableStringStreamImpl.java b/common/src/main/java/revxrsal/commands/stream/MutableStringStreamImpl.java index 051d6295..4fc8bd46 100644 --- a/common/src/main/java/revxrsal/commands/stream/MutableStringStreamImpl.java +++ b/common/src/main/java/revxrsal/commands/stream/MutableStringStreamImpl.java @@ -133,7 +133,9 @@ public void extend(@NotNull String str) { public float readFloat() { String value = readUnquotedString(); try { - return Float.parseFloat(value); + float v = Float.parseFloat(value); + if (Float.isFinite(v)) return v; + throw new InvalidDecimalException(value); } catch (NumberFormatException e) { throw new InvalidDecimalException(value); } @@ -142,7 +144,9 @@ public float readFloat() { public double readDouble() { String value = readUnquotedString(); try { - return Double.parseDouble(value); + double v = Double.parseDouble(value); + if (Double.isFinite(v)) return v; + throw new InvalidDecimalException(value); } catch (NumberFormatException e) { throw new InvalidDecimalException(value); }