XDXR-STREAM-RECORD-BOUNDS: require complete 16-byte StreamRecords in find_stream_record #484

Manually merged
github merged 1 commit from gh-pr/484/head into gh-pr/484/base 2026-11-26 09:03:27 +00:00
Owner

@⁠xroneyaa on GitHub · 2026-11-24 06:10 UTC · original
xroneyaa:fix/xdxr-stream-record-bounds → main · +16 −4 · 2 files · 1 commits · merged 2026-11-24 16:11 UTC

Claimed in the coordination issue as: XDXR-STREAM-RECORD-BOUNDS

What and why

leonida::xdxr::find_stream_record() in runtime/src/xdxr_descs.h computed end = reinterpret_cast<const StreamRecord*>(static_cast<const uint8_t*>(desc.stream) + desc.size_in_bytes) and looped for (; record < end; ++record). Whenever size_in_bytes was not a multiple of sizeof(StreamRecord) (16 bytes), the last iteration read a full 16-byte record past the caller's buffer end, and a very large size_in_bytes could wrap pointer addition.

This checks desc.size_in_bytes < sizeof(StreamRecord) || desc.stream == nullptr and iterates strictly over count = desc.size_in_bytes / sizeof(StreamRecord) complete records. Added boundary unit tests in runtime/test/xdxr_descs_test.cpp for sizes 1, 4, 15, 17, and 31 bytes.

Tested

  • Rebuilt xdxr_descs_test with MSVC 19.50 / Ninja (0 warnings)
  • ctest --test-dir runtime/build -R "^xdxr_descs$" --output-on-failure -> 1/1 Passed (0.01 s)
  • python -I scripts/check_no_game_data.py runtime/src/xdxr_descs.h runtime/test/xdxr_descs_test.cpp -> exit 0

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed (n/a — no translator rule added).
**@⁠xroneyaa** on GitHub · 2026-11-24 06:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/484) `xroneyaa:fix/xdxr-stream-record-bounds` → `main` · +16 −4 · 2 files · 1 commits · merged 2026-11-24 16:11 UTC Claimed in the coordination issue as: XDXR-STREAM-RECORD-BOUNDS ### What and why `leonida::xdxr::find_stream_record()` in `runtime/src/xdxr_descs.h` computed `end = reinterpret_cast<const StreamRecord*>(static_cast<const uint8_t*>(desc.stream) + desc.size_in_bytes)` and looped `for (; record < end; ++record)`. Whenever `size_in_bytes` was not a multiple of `sizeof(StreamRecord)` (16 bytes), the last iteration read a full 16-byte record past the caller's buffer end, and a very large `size_in_bytes` could wrap pointer addition. This checks `desc.size_in_bytes < sizeof(StreamRecord) || desc.stream == nullptr` and iterates strictly over `count = desc.size_in_bytes / sizeof(StreamRecord)` complete records. Added boundary unit tests in `runtime/test/xdxr_descs_test.cpp` for sizes `1`, `4`, `15`, `17`, and `31` bytes. ### Tested - Rebuilt `xdxr_descs_test` with MSVC 19.50 / Ninja (0 warnings) - `ctest --test-dir runtime/build -R "^xdxr_descs$" --output-on-failure` -> 1/1 Passed (0.01 s) - `python -I scripts/check_no_game_data.py runtime/src/xdxr_descs.h runtime/test/xdxr_descs_test.cpp` -> exit 0 GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed (n/a — no translator rule added).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:03:25 +00:00
github manually merged commit 36e9f9fce9 into gh-pr/484/base 2026-11-26 09:03:27 +00:00
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-24 10:39 UTC · original

Looks good. Counting whole records stops find_stream_record from reading a trailing partial StreamRecord (and from reading 16 bytes out of a stream shorter than one). Built xdxr_descs_test with g++ on Linux: it passes with the PR, and the PR's test fails against main's header, so it guards the change. Ship. AI-assisted review.

**@⁠Oliwettoo** on GitHub · 2026-11-24 10:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/484#issuecomment-7129063406) Looks good. Counting whole records stops `find_stream_record` from reading a trailing partial `StreamRecord` (and from reading 16 bytes out of a stream shorter than one). Built `xdxr_descs_test` with g++ on Linux: it passes with the PR, and the PR's test fails against `main`'s header, so it guards the change. Ship. AI-assisted review.
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-24 11:39 UTC · original

Independent run on Windows: passes.

Head 36e9f9fce built as it is (RelWithDebInfo, MSVC 19.50.35721.0): ctest -R xdxr_descs 1/1 passed, with and without LEONIDA_VK_VALIDATION=1. The diff reads right to me: a StreamRecord is accepted only when all 16 bytes fit, so a truncated tail no longer reads past the buffer.

GPU: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Vulkan 1.4.351, Windows 11 Pro 26300 (the test itself is CPU-only).

AI-assisted.

**@⁠kawaii-shakal** on GitHub · 2026-11-24 11:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/484#issuecomment-7130373590) Independent run on Windows: passes. Head 36e9f9fce built as it is (RelWithDebInfo, MSVC 19.50.35721.0): `ctest -R xdxr_descs` 1/1 passed, with and without `LEONIDA_VK_VALIDATION=1`. The diff reads right to me: a `StreamRecord` is accepted only when all 16 bytes fit, so a truncated tail no longer reads past the buffer. GPU: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Vulkan 1.4.351, Windows 11 Pro 26300 (the test itself is CPU-only). AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.