Skip to content

Commit 8d030da

Browse files
committed
Fix unexpected ArrayIndexOutOfBoundsException when writing java.time.ZonedDateTime values to java.nio.DirectByteBuffer or java.io.OutputStream using an internal buffer of small size
1 parent 65182b2 commit 8d030da

File tree

5 files changed

+5
-6
lines changed

5 files changed

+5
-6
lines changed

jsoniter-scala-core/js/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ final class JsonReader private[jsoniter_scala](
555555
* Reads a JSON number value into a `Byte` value.
556556
*
557557
* @return a `Byte` value of the parsed JSON value
558-
* @throws JsonReaderException in cases of reaching the end of input or dection of leading zero or
558+
* @throws JsonReaderException in cases of reaching the end of input or detection of leading zero or
559559
* illegal format of JSON value or exceeding capacity of `Byte`
560560
*/
561561
@inline

jsoniter-scala-core/js/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonWriter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,15 +2191,15 @@ final class JsonWriter private[jsoniter_scala](
21912191
pos = writeOffset(x.getOffset, writeLocalTime(x.toLocalTime, pos + 1, buf, ds), buf, ds)
21922192
val zone = x.getZone
21932193
if (!zone.isInstanceOf[ZoneOffset]) {
2194+
buf(pos) = '['
2195+
pos += 1
21942196
val zoneId = zone.getId
21952197
val len = zoneId.length
21962198
val required = len + 3
21972199
if (pos + required > limit) {
21982200
pos = flushAndGrowBuf(required, pos)
21992201
buf = this.buf
22002202
}
2201-
buf(pos) = '['
2202-
pos += 1
22032203
var i = 0
22042204
while (i < len) {
22052205
buf(pos) = zoneId.charAt(i).toByte

jsoniter-scala-core/jvm-native/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ final class JsonReader private[jsoniter_scala](
555555
* Reads a JSON number value into a `Byte` value.
556556
*
557557
* @return a `Byte` value of the parsed JSON value
558-
* @throws JsonReaderException in cases of reaching the end of input or dection of leading zero or
558+
* @throws JsonReaderException in cases of reaching the end of input or detection of leading zero or
559559
* illegal format of JSON value or exceeding capacity of `Byte`
560560
*/
561561
def readByte(): Byte = readByte(isToken = true)

jsoniter-scala-core/jvm-native/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonWriter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,14 +1961,14 @@ final class JsonWriter private[jsoniter_scala](
19611961
writeLocalTime(x.toLocalTime, writeLocalDateWithT(x.toLocalDate, pos + 1, buf, ds), buf, ds), buf, ds)
19621962
val zone = x.getZone
19631963
if (!zone.isInstanceOf[ZoneOffset]) {
1964+
buf(pos - 1) = '['
19641965
val zoneId = zone.getId
19651966
val len = zoneId.length
19661967
val required = len + 3
19671968
if (pos + required > limit) {
19681969
pos = flushAndGrowBuf(required, pos)
19691970
buf = this.buf
19701971
}
1971-
buf(pos - 1) = '['
19721972
zoneId.getBytes(0, len, buf, pos)
19731973
pos += len
19741974
ByteArrayAccess.setShort(buf, pos, 0x225D)

jsoniter-scala-core/shared/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReaderSpec.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,6 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
20582058
checkError(s""""+10:10:1${nonDigit}"""", "expected digit, offset: 0x00000009")
20592059
checkError(s""""+10:10:10${nonDoubleQuotes}"""", """expected '"', offset: 0x0000000a""")
20602060
}
2061-
20622061
}
20632062
}
20642063
"JsonReader.isCharBufEqualsTo" should {

0 commit comments

Comments
 (0)