From 2ab21f1e4bfeedd278feb86efa4869315c9a79d9 Mon Sep 17 00:00:00 2001 From: "shaojin.wensj" Date: Mon, 29 Jan 2024 16:11:01 +0800 Subject: [PATCH] fix json skipValue error, for issue #1257 --- .../alibaba/fastjson2/JSONReaderJSONB.java | 5 ++++ .../com/alibaba/fastjson2/jsonb/SkipTest.java | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java b/core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java index c6fd71634d..fab17c5f7c 100644 --- a/core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java +++ b/core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java @@ -2435,6 +2435,11 @@ public void skipValue() { return; } + if (type >= BC_INT32_SHORT_MIN && type <= BC_INT32_SHORT_MAX) { + offset += 2; + return; + } + if (type >= BC_STR_ASCII_FIX_MIN && type <= BC_STR_ASCII_FIX_MAX) { offset += (type - BC_STR_ASCII_FIX_MIN); return; diff --git a/core/src/test/java/com/alibaba/fastjson2/jsonb/SkipTest.java b/core/src/test/java/com/alibaba/fastjson2/jsonb/SkipTest.java index 86f7d8925f..1e7bb2ee7c 100644 --- a/core/src/test/java/com/alibaba/fastjson2/jsonb/SkipTest.java +++ b/core/src/test/java/com/alibaba/fastjson2/jsonb/SkipTest.java @@ -26,6 +26,33 @@ public void test_0() { assertNotNull(a); } + @Test + public void test_1() { + for (int i = 0; i < 100; i += 10) { + byte[] jsonbBytes = JSONObject.of("v", (byte) i).toJSONBBytes(); + A a = JSONB.parseObject(jsonbBytes, A.class); + assertNotNull(a); + } + + for (int i = 0; i < 1000; i += 10) { + byte[] jsonbBytes = JSONObject.of("v", (short) i).toJSONBBytes(); + A a = JSONB.parseObject(jsonbBytes, A.class); + assertNotNull(a); + } + + for (int i = 0; i < 100000; i += 10) { + byte[] jsonbBytes = JSONObject.of("v", i).toJSONBBytes(); + A a = JSONB.parseObject(jsonbBytes, A.class); + assertNotNull(a); + } + + for (int i = 0; i < 100000; i += 10) { + byte[] jsonbBytes = JSONObject.of("v", (long) i).toJSONBBytes(); + A a = JSONB.parseObject(jsonbBytes, A.class); + assertNotNull(a); + } + } + public static class A { } }