Protobuf: `nextName()` / `nextNameMatch()` do not skip an unread string value, decode its bytes as the next tag
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #878 de @cowtowncoder — fusionado
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 84/100
Línea de trabajo
Empieza en ProtobufParser.nextToken() y compara cómo omite un valor incompleto con nextName(), nextName(SerializableString) y nextNameMatch(PropertyNameMatcher). Reproduce el problema con el ejemplo proporcionado a nivel del parser, donde una cadena sin leer precede al campo a, y después añade pruebas para cada método y para el caso de databind. El trabajo estará terminado cuando esas llamadas lean a = 5 y pasen las pruebas del módulo protobuf.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.)
- Lenguaje dominante
- Java
- Estrellas
- 348
- Forks
- 159
- Merge medio
- 1 d 1 h
- PR fusionados (30 d)
- 37
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de FasterXML/jackson-dataformats-binary
-
2.21 cbor smile
Dificultad 3/5 1-2 días Aptitud para principiantes 67/100
FasterXML/jackson-dataformats-binary#888 ·
Los mantenedores suelen responder en 1 día
-
Update CBOR and Smile parsers to use padding variant of `BinaryNameMatcher` from jackson-coreAbierto3.3 cbor smile
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
FasterXML/jackson-dataformats-binary#887 ·
Los mantenedores suelen responder en 1 día
-
(smile) Cheap validation of short ASCII property names, to prevent symbol table bypassPosiblemente ocupada @cowtowncoder la tomó hace 1 día. Abierto3.3 performance smile
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
FasterXML/jackson-dataformats-binary#885 ·
Los mantenedores suelen responder en 1 día
-
protobuf
Dificultad 4/5 3-5 días Aptitud para principiantes 56/100
FasterXML/jackson-dataformats-binary#863 ·
Los mantenedores suelen responder en 1 día
-
avro
Dificultad 4/5 3-5 días Aptitud para principiantes 57/100
FasterXML/jackson-dataformats-binary#862 ·
Los mantenedores suelen responder en 1 día
Todos los issues de FasterXML/jackson-dataformats-binary
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Dans-Plugins/Medieval-Roleplay-Engine#384 ·
Los mantenedores suelen responder en 1 día
-
bug P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
:Search Relevance/Vectors >test-failure needs:risk Team:Search Relevance
Dificultad 2/5 1-3 horas Aptitud para principiantes 61/100
elastic/elasticsearch#163668 · 3 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Controller está sem anotaçãoAbiertobug critical
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
-
agent:working bug follow-up lane:auto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Sanne/incus-spawn#1765 · 2 comentarios ·
Los mantenedores suelen responder en 1 día