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

Aperta
#244 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
103
Fork
23
Merge medio
5g 8h
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Backblaze/b2-sdk-java

Tutte le issue di Backblaze/b2-sdk-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.