Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Protobuf: `nextName()` / `nextNameMatch()` do not skip an unread string value, decode its bytes as the next tag

Cerrado Apto para principiantes
#874 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java

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

protobuf

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de FasterXML/jackson-dataformats-binary

Todos los issues de FasterXML/jackson-dataformats-binary

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.