Add end-of-buffer boundary to container scanning helpers#63
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 *endparameter (one past the last valid byte). All*p != '\0'/*scan != '\0'loop guards and the backslash-at-EOF checks are replaced withp < end/scan < endcomparisons 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
endfromparser->json + parser->json_lenand pass it through. Unit tests that call the static helpers directly are updated to computeendfrom the test buffer's known size.https://claude.ai/code/session_01UNfWZ9r6cQRmMMqh9xasLX