runtime: guard null and invalid sizes in value_write_sink and add unit tests (RT-VALUE-WRITE-SINK-GUARDS-AND-TESTS) #2016

Merged
abnalstlll-byte merged 1 commit from upstream-pr/2016 into main 2026-11-30 17:15:20 +00:00
abnalstlll-byte commented 2026-11-25 18:12:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-25T18:12:19Z.


Claimed in the coordination issue as: RT-VALUE-WRITE-SINK-GUARDS-AND-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7170514927)

What and why

Harden runtime/src/value_write_sink.h and provide unit test coverage:

  • Guard arena() against null buffer pointers and non-4/8-byte sizes by immediately returning Landing::refused, preventing null dereference and invalid writes.
  • Guard title_pages() against null addresses, null bytes, and zero size by returning false immediately.
  • Guard clear_arena() against null device pointers (!device).
  • Add clear_title_pages() and reset_for_test() to allow clean state resets across tests and teardown.
  • Add portable CPU-only CTest unit test runtime/test/value_write_sink_test.cpp verifying initial state, guards, arena and title_pages dispatch, device-matched clearing, and multi-threaded concurrency.

Tested

  • g++ -std=c++20 -Wall -Wextra runtime/test/value_write_sink_test.cpp -> builds cleanly, runs and exits 0 (OK: value_write_sink_test passed all checks).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 4.676s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 11.795s, OK.
  • python -I scripts/check_no_game_data.py runtime/src/value_write_sink.h runtime/test/value_write_sink_test.cpp runtime/CMakeLists.txt -> exit 0.
  • git diff --check -> clean.

Tested on Windows 11 x64 (GCC C++20 / Python 3.12, stdlib tests, no game data needed).
AI-assisted (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5496672618 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2016). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-25T18:12:19Z. --- Claimed in the coordination issue as: RT-VALUE-WRITE-SINK-GUARDS-AND-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7170514927) ### What and why Harden `runtime/src/value_write_sink.h` and provide unit test coverage: - Guard `arena()` against null buffer pointers and non-4/8-byte sizes by immediately returning `Landing::refused`, preventing null dereference and invalid writes. - Guard `title_pages()` against null addresses, null bytes, and zero size by returning `false` immediately. - Guard `clear_arena()` against null device pointers (`!device`). - Add `clear_title_pages()` and `reset_for_test()` to allow clean state resets across tests and teardown. - Add portable CPU-only CTest unit test `runtime/test/value_write_sink_test.cpp` verifying initial state, guards, arena and title_pages dispatch, device-matched clearing, and multi-threaded concurrency. ### Tested - `g++ -std=c++20 -Wall -Wextra runtime/test/value_write_sink_test.cpp` -> builds cleanly, runs and exits 0 (`OK: value_write_sink_test passed all checks`). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 4.676s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 11.795s`, `OK`. - `python -I scripts/check_no_game_data.py runtime/src/value_write_sink.h runtime/test/value_write_sink_test.cpp runtime/CMakeLists.txt` -> `exit 0`. - `git diff --check` -> `clean`. Tested on Windows 11 x64 (GCC C++20 / Python 3.12, stdlib tests, no game data needed). AI-assisted (Claude Code)
MoonEyes commented 2026-11-28 02:48:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:48:45Z.


Hi @abnalstlll-byte, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/CMakeLists.txt), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232609246 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2016#issuecomment-7232609246). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:48:45Z. --- Hi @abnalstlll-byte, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/CMakeLists.txt`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
OreoFR commented 2026-11-30 13:40:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:40:32Z.


Carried as #2735 because of the conflict with main after #2566; @abnalstlll-byte, if you come back, say so and the carry is dropped.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7280190207 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2016#issuecomment-7280190207). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T13:40:32Z. --- Carried as #2735 because of the conflict with main after #2566; @abnalstlll-byte, if you come back, say so and the carry is dropped.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2016
No description provided.