Protobuf: `nextName()` / `nextNameMatch()` do not skip an unread string value, decode its bytes as the next tag
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #878 của @cowtowncoder — đã merge
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
Hướng nghiên cứu
Bắt đầu từ ProtobufParser.nextToken() và so sánh cách nó bỏ qua một giá trị chưa hoàn chỉnh với nextName(), nextName(SerializableString) và nextNameMatch(PropertyNameMatcher). Tái hiện lỗi bằng ví dụ ở cấp parser được cung cấp, trong đó một chuỗi chưa được đọc đứng trước trường a, rồi bổ sung kiểm thử cho từng phương thức và trường hợp databind. Hoàn tất khi các lời gọi đó đọc được a = 5 và các bài kiểm thử của mô-đun protobuf đều chạy qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
ProtobufParser.nextToken() starts by skipping the rest of a string or bytes value that was not read:
if (_tokenIncomplete) {
_tokenIncomplete = false;
_skipBytes(_decodedLength);
}
nextName(), nextName(SerializableString) and nextNameMatch(PropertyNameMatcher) do not. If the value before them was never accessed, its bytes are decoded as the next field tag.
This happens in databind whenever a string value is skipped without being read (for example a field in the schema that the bean does not have) and is followed by another field. Reproduced on 3.x (ab5956249); 3.2 is the same, and 2.x has the same omission in nextFieldName() and nextFieldName(SerializableString).
Reproduction
public static class Bean { public int a; }
ProtobufMapper m = ProtobufMapper.builder()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build();
ProtobufSchema schema = m.schemaLoader()
.parse("message M { optional string extra = 1; optional int32 a = 2; }");
Map<String, Object> value = new LinkedHashMap<>();
value.put("extra", "zz");
value.put("a", 5);
byte[] doc = m.writer(schema).writeValueAsBytes(value);
// Parser level
try (JsonParser p = m.reader(schema).createParser(doc)) {
p.nextToken(); // START_OBJECT
p.nextToken(); // PROPERTY_NAME "extra"
p.nextToken(); // VALUE_STRING, text not accessed
p.nextName(); // expected "a"
}
// Databind
m.readerFor(Bean.class).with(schema).readValue(doc);
| Call | Result |
|---|---|
nextToken() instead of nextName() |
name a, value 5 (correct) |
nextName() |
StreamReadException: Undefined property (id 15, wire type 2) for message type M: not allowed to ignore, as StreamReadFeature.IGNORE_UNDEFINED disabled |
readValue(doc) into Bean |
same exception (with IGNORE_UNDEFINED enabled: Unexpected end-of-input in VALUE_STRING) |
The tag id 15, wire type 2 is the string's own bytes, "zz" (0x7A), decoded as a tag.
Suggested fix
Add the same skip at the start of the three methods (and of the two nextFieldName() methods on 2.x):
// As in nextToken(): skip the rest of a value that was not read
if (_tokenIncomplete) {
_tokenIncomplete = false;
_skipBytes(_decodedLength);
}
With this change, both the parser-level and the databind cases read a = 5, and the protobuf module's tests pass (201 tests).
(Found while comparing stock databind with jackson-module-blackbird, which uses nextNameMatch() for every property name, including the first one and names in records.)
- Ngôn ngữ chính
- Java
- Star
- 348
- Fork
- 159
- Merge trung bình
- 1 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 45
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FasterXML/jackson-dataformats-binary
-
2.21 protobuf
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
FasterXML/jackson-dataformats-binary#894 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FasterXML/jackson-dataformats-binary#790 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
FasterXML/jackson-dataformats-binary#789 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
FasterXML/jackson-dataformats-binary#788 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FasterXML/jackson-dataformats-binary#766 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của FasterXML/jackson-dataformats-binary
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
intellij-elixir/intellij-elixir#4585 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
MetricsHub/metricshub-community#1474 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
adorsys/keycloak-config-cli#1742 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Booking links: POST /api/booking-links with a null element in "availabilityRules" throws NullPointerException and answers 500 instead of 400Có thể đã có người làm @chibenwa đã nhận hôm nay. Đang mởai-driven-fuzzing bug claude Minor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
linagora/twake-calendar-side-service#1322 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
PathnameExpander incorrectly interprets regex metacharacters in wildcard patternsCó thể đã có người làm @jiteshkhatri11 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
javapathfinder/jpf-core#662 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày