Skip to content

Fixed the reading of arrays referenced more than once in v2 - #72

Merged
tcalmant merged 1 commit into
masterfrom
fix-v2-reference-handle
Aug 12, 2026
Merged

Fixed the reading of arrays referenced more than once in v2#72
tcalmant merged 1 commit into
masterfrom
fix-v2-reference-handle

Conversation

@tcalmant

Copy link
Copy Markdown
Owner

Summary

Three problems prevented v2 from reading a stream where the same array is
stored in two fields:

  • _do_array() gave a handle to the array but never stored it, so any
    reference to that array failed with Invalid reference handle. This is
    what the handles "spaced out by 2" in the report come from: the numbers
    were given to the arrays, but nothing was kept for them.
  • _read_field_value() read a TC_REFERENCE found in an array field with
    _do_classdesc(), which requires a class description and rejected the
    array with Referenced object is not a class description.
  • Class descriptions were stored only after their annotations and their
    super class had been read, so nothing read in between could refer to them.
    They are now stored as soon as they are created, as v3 already does.

The first two are what the reported file hits; the last one is the same kind
of problem, found while comparing with v3, and is fixed for consistency.

With those, v2 reads the 2.2 MB session attached to the issue completely.

Test plan

  • New testSharedArray.ser fixture, and SharedArrayExample.java
    documenting how it is built: a byte array and a string array, each stored
    in two fields, followed by an int field which detects a desynchronized
    stream.
  • Checked that the fixture reproduces the reported error before the fix
    (Invalid reference handle: 7e0005) and passes after it.
  • test_shared_array added to the v2 and v3 test suites: both check the
    values, that the two fields give the very same array, and the field
    written after them.
  • Checked on the session file attached to the issue: it now parses.

Fixes #62

Arrays were given a handle but were never stored, so a reference to an array could not be resolved. A reference found in an array field was also read as a class description instead of the array itself. Class descriptions are now stored before their annotations, as v3 already does. Fixes #62.

Signed-off-by: Thomas Calmant <thomas.calmant@gmail.com>
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 92.298% (+0.07%) from 92.232% — fix-v2-reference-handle into master

@tcalmant
tcalmant merged commit 83d7d58 into master Aug 12, 2026
15 checks passed
@tcalmant
tcalmant deleted the fix-v2-reference-handle branch August 12, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After fixing #60, I noticed that it fails with invalid references (in v2)

2 participants