Skip to content

Add end-of-buffer boundary to container scanning helpers#63

Merged
ionux merged 1 commit intomainfrom
claude/fix-container-boundary-checks-l0FAQ
Mar 21, 2026
Merged

Add end-of-buffer boundary to container scanning helpers#63
ionux merged 1 commit intomainfrom
claude/fix-container-boundary-checks-l0FAQ

Conversation

@ionux
Copy link
Copy Markdown
Owner

@ionux ionux commented Mar 21, 2026

okj_skip_string, okj_count_array_elements, okj_count_object_members, and okj_measure_container previously scanned forward relying solely on a '\0' sentinel, which could read past the parser's json_len boundary.

Each function now accepts a const char *end parameter (one past the last valid byte). All *p != '\0' / *scan != '\0' loop guards and the backslash-at-EOF checks are replaced with p < end / scan < end comparisons so the scan is bounded by the same region the main parser uses.

Callers (okj_get_array, okj_get_object, okj_get_array_raw, okj_get_object_raw, okj_debug_print) now derive end from parser->json + parser->json_len and pass it through. Unit tests that call the static helpers directly are updated to compute end from the test buffer's known size.

https://claude.ai/code/session_01UNfWZ9r6cQRmMMqh9xasLX

okj_skip_string, okj_count_array_elements, okj_count_object_members, and
okj_measure_container previously scanned forward relying solely on a '\0'
sentinel, which could read past the parser's json_len boundary.

Each function now accepts a `const char *end` parameter (one past the last
valid byte).  All `*p != '\0'` / `*scan != '\0'` loop guards and the
backslash-at-EOF checks are replaced with `p < end` / `scan < end`
comparisons so the scan is bounded by the same region the main parser uses.

Callers (okj_get_array, okj_get_object, okj_get_array_raw, okj_get_object_raw,
okj_debug_print) now derive `end` from `parser->json + parser->json_len` and
pass it through.  Unit tests that call the static helpers directly are updated
to compute `end` from the test buffer's known size.

https://claude.ai/code/session_01UNfWZ9r6cQRmMMqh9xasLX
@ionux ionux merged commit e433d5a into main Mar 21, 2026
3 checks passed
@ionux ionux deleted the claude/fix-container-boundary-checks-l0FAQ branch March 21, 2026 00:09
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.

2 participants