Skip to content

JavaBinarySerializer.writeExternal writes a property count that doesn't match the bytes written #4328

@ruispereira

Description

@ruispereira

Affected version: 26.4.2 (confirmed still present in 26.5.1)
Component: com.arcadedb.serializer.JavaBinarySerializer

Summary

The writer increments properties.size() as the property count at the start, then skips writing the size/payload bytes for properties where propValue == null or where the type cannot be inferred (type == -1). The reader iterates propertyCount times and reads UTF + int + bytes for each — so a single skipped property desyncs every subsequent read.

Code

engine/com/arcadedb/serializer/JavaBinarySerializer.java:57–86, 123–129

out.writeInt(properties.size());                        // count includes every entry
for (Map.Entry<String, Object> prop : properties.entrySet()) {
  out.writeUTF(propName);                               // always written
  if (propValue != null) {
    …
    if (type == -1) { log.warn(…); continue; }          // size/payload NOT written
    out.writeInt(buffer.size());
    out.write(buffer.getContent(), 0, buffer.size());
  }
  // null values: size/payload NOT written either
}

// readExternal:
final int propertyCount = in.readInt();
for (int i = 0; i < propertyCount; i++) {
  final String propName = in.readUTF();
  final int propertySize = in.readInt();
  final byte[] array = new byte[propertySize];
  in.read(array);                                       // see issue #10
  …
}

Impact

Any document with a null-valued or un-serializable property deserializes into garbage (wrong property names mapped to wrong bytes) or throws somewhere downstream with an opaque message.

Suggested fix

Filter the map down to serializable, non-null properties; write the filtered count and only filtered entries.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions