fix: use absolute value for scale in minCapacity calculation in JSONWriterUTF8 and JSONWriterUTF16 otherwise buffer may overflow

This commit is contained in:
Anil Halil 2025-04-28 15:26:39 +03:00 committed by Shaojin Wen
parent 229fab094a
commit e3eebee8be
2 changed files with 2 additions and 2 deletions

View File

@ -1061,7 +1061,7 @@ class JSONWriterUTF16
boolean writeAsString = isWriteAsString(value, features);
int off = this.off;
int minCapacity = off + precision + value.scale() + 7;
int minCapacity = off + precision + Math.abs(value.scale()) + 7;
char[] chars = this.chars;
if (minCapacity > chars.length) {
chars = grow(minCapacity);

View File

@ -2387,7 +2387,7 @@ final class JSONWriterUTF8
boolean writeAsString = isWriteAsString(value, features);
int off = this.off;
int minCapacity = off + precision + value.scale() + 7;
int minCapacity = off + precision + Math.abs(value.scale()) + 7;
byte[] bytes = this.bytes;
if (minCapacity > bytes.length) {
bytes = grow(minCapacity);