Validate embedded objects for ZoneId, Period and ZoneOffset
まだ誰も着手していません。
評価
調査の方向性
Start with JSR310StringParsableDeserializer and its VALUE_EMBEDDED_OBJECT branch, then reproduce the behavior using the CBOR generic Map<String, ZoneId> example and the corresponding List, Period, and ZoneOffset cases. Done means compatible embedded values still deserialize, while incompatible values are rejected with a normal Jackson mapping exception.
索引モデルが issue の本文から書いたものです。
説明
Description
As requested after reporting this by email, I am filing it here as a regular validation bug.
JSR310StringParsableDeserializer returns JsonParser.getEmbeddedObject() without checking that the returned object matches the requested type. With a binary data format and a type-erased generic container, this allows (for example) a CBOR byte string to be stored as the value of a Map<String, ZoneId> without any exception.
This affects the shared deserializer used for ZoneId, Period, and ZoneOffset.
Version information
jackson-datatype-jsr310: 2.22.2jackson-dataformat-cbor: 2.19.2- Java 8
The behavior was also reproduced against the current 2.x branch (2.23.0-SNAPSHOT).
Minimal reproduction
ObjectMapper mapper = new ObjectMapper(new CBORFactory());
mapper.registerModule(new JavaTimeModule());
ByteArrayOutputStream out = new ByteArrayOutputStream();
CBORGenerator gen = new CBORFactory().createGenerator(out);
gen.writeStartObject();
gen.writeFieldName("zone");
gen.writeBinary(new byte[] {
(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF
});
gen.writeEndObject();
gen.close();
Map<String, ZoneId> result = mapper.readValue(
out.toByteArray(),
new TypeReference<Map<String, ZoneId>>() { });
Object value = result.get("zone");
System.out.println(value.getClass());
System.out.println(value instanceof byte[]);
Output:
class [B
true
The same behavior occurs for a List<ZoneId> and for the Period and ZoneOffset deserializers.
Expected behavior
The embedded object should be accepted only if it is compatible with the requested target type. An incompatible value should produce a normal Jackson mapping exception, such as MismatchedInputException.
Actual behavior
The raw byte[] is returned and inserted into the generic container. No exception is raised during deserialization.
A directly typed POJO field does fail because reflective field assignment performs an independent runtime type check. Generic map values and collection elements do not have that check because of type erasure.
Cause
The VALUE_EMBEDDED_OBJECT branch returns the object directly:
} else if (p.hasToken(JsonToken.VALUE_EMBEDDED_OBJECT)) {
return p.getEmbeddedObject();
}
JSR310StringParsableDeserializer extends JSR310DeserializerBase<Object>, so no compiler-generated cast validates the returned value. The other JSR-310 deserializers that explicitly cast their embedded values fail immediately instead of silently placing the wrong type in the container.
One possible fix is to verify the embedded value against handledType() / _valueClass and route an incompatible value through DeserializationContext.handleUnexpectedToken(...).
- 主要言語
- Java
- スター
- 425
- フォーク
- 125
- 平均マージ
- 19分
- マージ済み PR(30日)
- 1
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
FasterXML/jackson-modules-java8 のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
FasterXML/jackson-modules-java8#382 · コメント 3 件 ·
-
date-time-config
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
FasterXML/jackson-modules-java8#374 · コメント 31 件 · リアクション 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
FasterXML/jackson-modules-java8#310 · コメント 1 件 ·
-
test-needed
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
FasterXML/jackson-modules-java8#304 · コメント 3 件 ·
-
pr-welcome test-needed
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
FasterXML/jackson-modules-java8#299 · コメント 4 件 · リアクション 1 件 ·
FasterXML/jackson-modules-java8 の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
elastic/gradle-plugins#157 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
cryptomator/hub#497 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
johanhaleby/occurrent#1120 ·