JSON union reader checks only the last unknown field, so field order decides

Đang mở
#244 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend

Hướng nghiên cứu

Start in core/src/main/java/com/backblaze/b2/json/B2JsonUnionBaseHandler.java. Read the read loop around line 350, where unknownFieldNameOrNull is overwritten on each unknown field, and the check after the loop around line 384. Add a test that deserializes an object with two unknown fields in both orders under ERROR mode, with a discard list, and confirm the outcomes differ. It is done when both orders give the same, correct result and the test passes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

What happens

While reading a union object with ExtraFieldOption.ERROR, each unknown field overwrites a single unknownFieldNameOrNull variable, and only the last one is checked against the fields that may be discarded. If an object has two unknown fields, a non-discardable unknown field that comes before a discardable one is accepted, so the result depends on field order.

Where

core/src/main/java/com/backblaze/b2/json/B2JsonUnionBaseHandler.java:350 (assignment in the read loop) and :384 (the check after the loop).

Why it matters

Impact: Wrong request or result (an unknown field is accepted that should be rejected), silent when accepted. Severity: Medium, because it needs ERROR mode, a discard list and two or more unknown fields (unusual), and the SDK's own responses are read in the lenient mode.

How to check

Found by reading the code, not reproduced. Read the loop and the check after it. A test could deserialize {"type":"x","bad":1,"discardable":2} and the same object with the two fields swapped, with ERROR mode, and compare the outcomes. Collecting all unknown names, or checking each one as it is read, would fix it.

Version

Seen at v6.5.0. Present on the default branch: present.

Ngôn ngữ chính
Java
Star
103
Fork
23
Merge trung bình
5 ngày 8 giờ
Pull request đã merge (30 ngày)
3

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Backblaze/b2-sdk-java

Tất cả issue của Backblaze/b2-sdk-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.