Skip to content

Conversation

@akx
Copy link
Contributor

@akx akx commented Oct 8, 2025

Idea based on the patch in orjson.

When no limit is compiled in, there is no performance impact.

I didn't add a test case (seemed pretty hairy to do so while keeping the rest of the tests intact, but let me know if there's a neat way to do that), but there's an "experiment" file you can run:

Use e.g.

cmake -B cmake-build-limit . -D YYJSON_BUILD_MISC=true -D YYJSON_BUILD_TESTS=false -D YYJSON_READER_DEPTH_LIMIT=50
cmake --build cmake-build-limit
./cmake-build-limit/experiment_depth_limit

to see this in action:

Parsing: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[8]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], depth limit = 50
=> Error code: 15
Parsing: {"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":{"n":{"o":{"p":{"q":{"r":{"s":{"t":{"u":{"v":{"w":{"x":{"y":{"z":{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":{"l":{"m":{"n":{"o":{"p":{"q":{"r":{"s":{"t":{"u":{"v":{"w":{"x":{"y":8}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}, depth limit = 50
=> Error code: 15

Idea based on the patch in orjson by ijl.
@codecov
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.34%. Comparing base (351b5d7) to head (395e0f2).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/yyjson.c 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #235      +/-   ##
==========================================
- Coverage   98.53%   98.34%   -0.20%     
==========================================
  Files           2        2              
  Lines        9098     9102       +4     
==========================================
- Hits         8965     8951      -14     
- Misses        133      151      +18     
Flag Coverage Δ
unittests 98.34% <0.00%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@akx
Copy link
Contributor Author

akx commented Oct 9, 2025

windows_msvc seems to be complaining about "warning C4702: unreachable code"... I guess that'd be the bail-out goto targets that can't be reached unless a limit is compiled in. Should I make the warning be ignored for those lines, or those goto targets also be conditionally compiled in?

@ibireme
Copy link
Owner

ibireme commented Oct 9, 2025

windows_msvc seems to be complaining about "warning C4702: unreachable code"... I guess that'd be the bail-out goto targets that can't be reached unless a limit is compiled in. Should I make the warning be ignored for those lines, or those goto targets also be conditionally compiled in?

Since we already have several warning suppressions, I'm okay with using #pragma warning(disable:4702) for this.

@akx
Copy link
Contributor Author

akx commented Oct 10, 2025

Since we already have several warning suppressions, I'm okay with using #pragma warning(disable:4702) for this.

Alright. Would you prefer warning(push)/warning(disable:4702)/warning(pop) around the 4 bail-out sections, or globally in the file?

@ibireme
Copy link
Owner

ibireme commented Oct 10, 2025

Could add here globally:

yyjson/src/yyjson.c

Lines 44 to 50 in 351b5d7

#elif defined(_MSC_VER)
# pragma warning(disable:4100) /* unreferenced formal parameter */
# pragma warning(disable:4101) /* unreferenced variable */
# pragma warning(disable:4102) /* unreferenced label */
# pragma warning(disable:4127) /* conditional expression is constant */
# pragma warning(disable:4706) /* assignment within conditional expression */
#endif

@akx
Copy link
Contributor Author

akx commented Oct 16, 2025

Added the pragma – sorry for the delay, didn't get a notification of your reply.

@ibireme ibireme merged commit 210302f into ibireme:master Oct 16, 2025
40 of 42 checks passed
@akx akx deleted the depth-limit branch October 16, 2025 11:07
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