Add substr bounds validation to prevent out-of-bounds exceptions#8821
Open
directionless wants to merge 1 commit into
Open
Add substr bounds validation to prevent out-of-bounds exceptions#8821directionless wants to merge 1 commit into
directionless wants to merge 1 commit into
Conversation
|
|
3f62dd7 to
271d8ce
Compare
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
271d8ce to
a5a043f
Compare
zwass
reviewed
Apr 15, 2026
| // Iterate over each space-tokenized argument. | ||
| for (const auto& argument : arguments) { | ||
| if (argument.substr(0, 11) == "BOOT_IMAGE=") { | ||
| if (argument.size() >= 11 && argument.substr(0, 11) == "BOOT_IMAGE=") { |
zwass
reviewed
Apr 15, 2026
| if (argument.size() >= 11 && argument.substr(0, 11) == "BOOT_IMAGE=") { | ||
| r["path"] = argument.substr(11); | ||
| } else if (argument.substr(0, 5) == "root=") { | ||
| } else if (argument.size() >= 5 && argument.substr(0, 5) == "root=") { |
zwass
requested changes
Apr 15, 2026
Member
zwass
left a comment
There was a problem hiding this comment.
Lots of good fixes here. Some changes requested.
Comment on lines
91
to
96
| auto value_key = subkey.substr(count_key); | ||
| if (value_key.size() < 6) { | ||
| LOG(WARNING) << "Value key too short"; | ||
| continue; | ||
| } | ||
| std::string value_key_reg = value_key.substr(6, std::string::npos); |
Member
There was a problem hiding this comment.
Suggested change
| auto value_key = subkey.substr(count_key); | |
| if (value_key.size() < 6) { | |
| LOG(WARNING) << "Value key too short"; | |
| continue; | |
| } | |
| std::string value_key_reg = value_key.substr(6, std::string::npos); | |
| if (subkey.size() < count_key + 6) { | |
| LOG(WARNING) << "Value key too short"; | |
| continue; | |
| } | |
| std::string value_key_reg = subkey.substr(count_key + 6); |
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.
This commit adds comprehensive bounds checking before all substr() operations across multiple files to prevent std::out_of_range exceptions when processing malformed or incomplete data.
Changes:
The pattern used is to check string size before substr operations and handle std::string::npos from find() operations before using the result in arithmetic or substr calls. When validation fails, appropriate error messages are logged and safe fallback values are returned.
🤖 Generated with Claude Code
To submit a PR please make sure to follow the next steps:
CONTRIBUTING.mdguide at the root of the repo.format_checktarget.If it is not, then move the committed files to the git staging area,
build the
formattarget to format them, and then re-commit.More information is available on the wiki.