Skip to content

bcpack: BCPack refusal inspector review follow-up - #3346

Open
romn4rch wants to merge 8 commits into
R0Y00:mainfrom
romn4rch:copilot/pr-1940-review-f8d2d51e
Open

romn4rch wants to merge 8 commits into
R0Y00:mainfrom
romn4rch:copilot/pr-1940-review-f8d2d51e

Conversation

@romn4rch

Copy link
Copy Markdown
Contributor

Alternate review revision for #1940. This branch contains the existing BCPack inspector work plus verified review fixes and consistency checks. The original PR remains open because its author-owned branch was not writable from this account; these submissions overlap, so please keep only one and close/mark the other as superseded when choosing.

Validation: git diff --check and the Python consistency check across inspector, decoder, and fixture lane tables passed. C++ tests were not run because the required MSVC cl toolchain is unavailable in this environment.

tedin7 and others added 8 commits November 25, 2026 04:28
decode_lanes can fill an optional LaneReport saying why it stopped and how far the lanes got; without
one it behaves as before. bcpack_inspect.h turns that into a class for a request (destination size
not a whole number of blocks, request shorter or longer than the stream, a cut stream, trailing input,
and so on) with the bytes read and the symbols per lane. decode_bcpack and the request path are
unchanged. The check runs the repository's synthetic BC1 and BC7 streams; its collapse control
reports every failure as one class and must fail.
…R0Y00#1198)

A 256 MiB BC7 declaration let a tiny source allocate about 1 GiB of lane
symbols. The cap is now the shared 16 MiB chunk-window bound; larger
declarations return bad_arguments before any allocation. Adds oversized
declared-output cases; short/long/truncated controls unchanged.
…cpack uses

A failing BC3, BC4 or BC5 request was reported as unsupported_format. The reason now comes from the lane state, as for BC1 and BC7.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean cold-path inspector that names the class of BCPack failure.

  • LaneFailure enum and LaneReport struct thread through decode_lanes_reference with note() and stall_failure() helpers.
  • New bcpack_inspect.h is independent of the hot path: runs the lane decode with a report, maps failures to InspectClass, supports BC1–BC7.
  • 16 MiB output cap prevents oversized scratch allocation before any decode.
  • bcpack_inspect_check.cpp covers exact/truncated/padded/damaged streams for BC1/BC7 plus BC2/BC3/BC4/BC5/BC6 edge cases, with a --mutate collapse negative control.

The inspector is a pure read of lane state — no request-path changes.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean cold-path inspector that names the class of BCPack failure.

  • LaneFailure enum and LaneReport struct thread through decode_lanes_reference with note() and stall_failure() helpers.
  • New bcpack_inspect.h is independent of the hot path: runs the lane decode with a report, maps failures to InspectClass, supports BC1–BC7.
  • 16 MiB output cap prevents oversized scratch allocation before any decode.
  • bcpack_inspect_check.cpp covers exact/truncated/padded/damaged streams for BC1/BC7 plus BC2/BC3/BC4/BC5/BC6 edge cases, with a --mutate collapse negative control.

The inspector is a pure read of lane state — no request-path changes.

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head f8d2d51e by reading its diff against main 212d4b5f. Nothing was built or run. git merge-tree --write-tree origin/main f8d2d51e exits 0.

Checked by reading

  • INSPECT_LAYOUTS (bcpack_inspect.h:59-67) matches decode_bcpack on main for all seven formats: the alphabets table (bcpack_decoder.h:1391-1399), the lane counts (:1404), the block sizes (:1400) and the per-lane target output_size / 8 (:1403).
  • Every return false in decode_lanes_reference now records a failure first (bcpack_decoder.h:280, 285, 379, 399, 405, 419, 423 at head).
  • phase1 returns false in two places only: :165 (eab > 8) and :230 (flushed fragment not at the home state, reached only after a header with eab <= 8). The ln.eab > 8 test at head :378 therefore separates header_invalid from fragment_not_home exactly.
  • The block-stage note in the header holds. BC1 to BC5 refuse only on capacity or symbol count. BC6H refuses a mode outside 1 to 14 (bcpack_blocks_extra.inl:108, mode = symbol + 1). BC7 refuses an unmapped control code (bcpack_decoder.h:1104 at head).
  • The new cases test what their names say. Symbol 13 is mode 14, which is valid, and symbol 14 is mode 15, which is not. symbols[30] = 31, symbols[31] = 3 gives code (3 << 5) | 31 = 0x07f, whose table entry has valid = 0 (bcpack_tables.h:975).
  • decode_bcpack is unchanged, and decode_lanes without a report takes the same path as before. No refusal is removed.

Needs a run before merge

  • On pull requests the workflow runs cmake --build --preset pr and ctest --preset pr (windows.yml:490-493). In CMakePresets.json the pr build targets (:28-38) do not include bcpack_inspect_check, and the pr test filter (:51) matches no bcpack_inspect name. The PR description says the C++ tests were not run. So nothing shows that test_bc2_bc6_bc7 and test_inspect_layouts compile or pass at this head. Please post a dev run of ctest -R "^bcpack_inspect" at f8d2d51e (2 tests, the collapse control is WILL_FAIL).

Relation to #1940

  • The description presents this PR as an alternate revision of #1940. It carries #1940's commits up to 7de1131b plus one commit, and it edits the same four files.
  • #1940 has since moved to 23ab9d48, which also adds the BC2 and BC6H layouts. Two differences remain between the heads:
    • This PR gives the BC6H mode failure its own class, bc6_mode_invalid. #1940 reports it as control_code_unmapped.
    • #1940's test_all_formats_agree runs a 17-block fixture stream for each of formats 1 to 7, checks ok and request_shorter_than_stream, and compares each answer with decode_bcpack. Here BC2 and BC6H get a 1-block exact case, and the two block-stage failures are 1-block cases.
  • Only one of the two should merge.

Minor

  • inspect_bcpack maps lanes_ok == false with failure == none to ok (bcpack_inspect.h:136-138). No exit leaves none today. Mapping that case to a failure class would keep a future exit without note() from reporting ok.
  • The C++ test is registered inside the if(EXISTS "${INTAKE_PYTHON}") block but needs no Python. bcpack_encoder_check is registered outside it.
  • At bcpack_decoder.h:328, !met && is redundant after if (met) return.

No defect found by reading f8d2d51e. Open before merge: the dev run of the two bcpack_inspect tests, and the choice between this PR and #1940.

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.

4 participants