Repository navigation
[#719] Avoid quadratic strlen in JSON parser - #720
Open
hardikkaurani wants to merge 1 commit into
Open
hardikkaurani wants to merge 1 commit into
hardikkaurani wants to merge 1 commit into
Conversation
Contributor
Author
|
@jesperpedersen Hi Jesper, whenever you have a chance to take a look, this PR addresses #719 to optimize JSON parsing performance and edge-case handling. Key changes:
All JSON test cases pass cleanly, code formatting matches |
Collaborator
hardikkaurani
force-pushed
the
fix/avoid-quadratic-strlen-json-719
branch
from
December 2, 2026 21:31
9f22ed5 to
030b9a8
Compare
Contributor
Author
|
@Pranav-error Rebased onto |
Pass the string length down to parse_string() and fill_value() rather than calling strlen() repeatedly on every object, array, and value encountered during JSON parsing. Also validate that the output pointer is non-NULL in pgexporter_json_parse_string() and initialize *obj = NULL. Add regression tests in test/testcases/test_json.c covering NULL and short-string input bounds and nested object/array parsing. Signed-off-by: Hardik Kaurani <[email protected]>
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.
Closes #719
Summary
src/libpgexporter/json.c, measure the JSON string length once inpgexporter_json_parse_string()and passlendown toparse_string()andfill_value().strlen(str)calls across recursive parsing of objects, arrays, and values, eliminating O(N^2) quadratic scanning overhead on large or nested JSON documents.obj == NULLinpgexporter_json_parse_string()and initialize*obj = NULLto prevent null pointer dereferences and uninitialized output pointers on failure.test/testcases/test_json.c:test_json_parse_string_null_and_bounds: validates error handling andNULLassignment forNULLoutput pointer,NULLstring, empty string, and incomplete JSON.test_json_parse_string_nested: validates nested objects and arrays parsing.Verification
src/libpgexporter/json.candtest/testcases/test_json.cwithclang-format(clang-format --dry-run --Werrorpassed).git diff --checkwith 0 whitespace errors.upstream/main.