Conversation
ytkg
reviewed
Jan 6, 2026
lib/jsonc.rb
Outdated
| end | ||
|
|
||
| def self.load_file(path, **opts) | ||
| max_bytes = opts.fetch(:max_bytes, DEFAULT_MAX_BYTES) |
Owner
There was a problem hiding this comment.
Was the difference in handling max_bytes intentional?
load_file uses opts.fetch(:max_bytes, DEFAULT_MAX_BYTES), so passing max_bytes: nil results in max_bytes being nil and file_size > max_bytes can raise a TypeError.
Contributor
Author
There was a problem hiding this comment.
Not sure why, great spot, thanks. I've added tests for parse and load_file max_bytes: nil.
Owner
There was a problem hiding this comment.
Thank you. I will release it soon as version 0.2.0.
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.
What?
Added input size limit protection to help prevent memory exhaustion DoS attacks. The max_bytes option (default: 10MB) can be configured in both JSONC.parse and JSONC.load_file methods to reject excessively large inputs that could crash applications processing untrusted JSONC files.
Why?
Memory exhaustion is a security and reliability concern where crafted large inputs can exhaust application memory and cause denial-of-service attacks. Without size limits, an attacker could submit a multi-gigabyte JSONC file that would crash the server during preprocessing. The fix ensures graceful rejection of oversized inputs while providing flexibility for legitimate large files.
How?
Added size checks before parsing that validate input size against configured limit. The implementation:
Note: The size limit applies to raw JSONC input (including comments and whitespace) before sanitization.
Testing?
Added 6 new test cases covering:
All 18 tests pass (12 existing + 6 new). Tests verify both positive and negative cases for default and custom limits across both parse and load_file methods.
Anything Else?
No, thanks.