Skip to content

fix(cpp): read chunk headers with long column names - #1167

Open
ColinLeeo wants to merge 1 commit into
apache:developfrom
ColinLeeo:colin/fix-long-column-name-read
Open

ColinLeeo wants to merge 1 commit into
apache:developfrom
ColinLeeo:colin/fix-long-column-name-read

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A table-model column name of 1018 or more characters made the write succeed but the read return E_PARTIAL_READ, i.e. a file that is silently unreadable.

Root cause

The chunk header embeds the measurement name. The reader parsed chunk headers through a fixed 1024-byte window. For a header of chunk_type(1) + varint len(2) + name + data_size varint(1) + 3 bytes, a name of 1017 bytes fits in 1024, while 1018 bytes needs 1025 — read_var_str then returned E_PARTIAL_READ because the chunk-header path had no grow-and-retry window (chunk/page header reads did).

Changes

  • Add a bounded (1 MiB cap) doubling read-window helper for chunk headers and wire it into ChunkReader, the aligned single-value/multi-value chunk readers, and the restorable recovery scan; keeps E_PARTIAL_READ semantics for truncated data and the same cursor/offset behavior.
  • Recovery: fail on E_OOM instead of treating it as a corrupt tail and truncating a valid file; release the in-progress device id on that path.
  • Regression tests: long FIELD/TAG names at 1017/1018/1024/4096, corrupted length varints, EOF/partial paths, OOM injection, plus value-level assertions for the multi-column table path.

Verification

  • Debug full C++ gtest: 1917 passed / 0 failed (2 compat cases need the repository cwd).
  • Pre-fix differential: 1018/1024/4096 reproduce the failure, 1017 passes — the threshold matches the analysis.
  • clang-format 17.0.6 clean; independent LSan rerun reports 0 leaks.

Review

Self-reviewed, then an independent read-only review; the delta review concluded "mergeable". The change also incorporates the review hardening (bounded read window, OOM recovery) and the OOM cleanup found by LeakSanitizer.

A serialized chunk header embeds the measurement/column name verbatim, so a
column/measurement name of about 1018 characters or more makes the header
longer than the fixed 1024-byte window used by ChunkReader::load_by_meta(),
AlignedChunkReader::load_by_aligned_meta() and
AlignedChunkReader::load_by_aligned_meta_multi(). Reading the header then hit
read_var_str()'s "length beyond the stream" check, which surfaces
E_PARTIAL_READ: the write succeeded but the first read of that column failed.

Add reader/read_chunk_header.h: it reads and deserializes a chunk header at an
offset, doubling the read window while deserialization reports that more bytes
are needed, capped at 1 MiB and at the end of the file. Use it in both chunk
readers and in the recovery self-check (parse_chunk_header_and_skip()) as well,
which previously mistook such a chunk for a corrupt tail and truncated the
recovered file at it. Callers wrap the returned buffer and advance their stream
past header.serialized_size_ to the first page header.

Recovery hardening: an allocation failure (E_OOM) during the recovery scan now
fails recovery instead of being treated as a corrupt tail, and the in-progress
device id is released on that path so LeakSanitizer stays clean.

No on-disk format or writer change: names that could already be written are now
readable again, matching Java, which has no name length limit.

Tests: new LongMeasurementNameTest writes and reads back 1017/1018/1024/4096
character names for table FIELD and TAG columns and tree measurements; new
restorable-writer cases recover and append after a 4096-character name and
inject an OOM during the self-check. The FIELD, tree and recovery cases fail
below the boundary without this fix; the TAG case is coverage only, since tag
values come from the device id rather than a value chunk.

Known limitations left for a separate change: chunk-group headers in the
recovery self-check still use a fixed 4096-byte window, and a chunk header
larger than the 1 MiB cap can be written but not read or recovered.
@ColinLeeo
ColinLeeo force-pushed the colin/fix-long-column-name-read branch from 1185d0d to 318ad87 Compare December 1, 2026 03:00
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.

1 participant