Array out of bounds fix - #471
Closed
keerthimuvva52 wants to merge 1 commit into
Closed
Conversation
keerthimuvva52
requested review from
DetiPrudvi08,
alexanderintc,
Copilot,
nirint and
shubhangi-shrivastava
July 17, 2026 05:54
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds additional validation during database deserialization to prevent out-of-bounds access at scan time by ensuring LimEx reach-map indices are within the associated reach table size.
Changes:
- Introduces
db_validate_limex_reach_map()to validate LimExreachMap[]entries againstreachSize. - Hooks the new validation into
db_validate_rose_offsets()so corrupted databases fail validation earlier.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+306
to
+320
| if (!isNfaType(nfa->type)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (unlikely(ni->nfaOffset + nfa->length > rose_size)) { | ||
| return HS_INVALID; | ||
| } | ||
|
|
||
| if (unlikely(nfa->length <= sizeof(struct NFA))) { | ||
| return HS_INVALID; | ||
| } | ||
|
|
||
| const char *limex_base = (const char *)getImplNfa(nfa); | ||
| u32 limex_len = nfa->length - (u32)sizeof(struct NFA); | ||
|
|
Comment on lines
+329
to
+330
| const struct LimExNFA32 *limex = | ||
| (const struct LimExNFA32 *)limex_base; |
Comment on lines
+321
to
+327
| /* Ensure we can read reachMap[256] and reachSize. */ | ||
| const u32 reach_prefix_end = | ||
| (u32)(N_CHARS + sizeof(u32)); /* reachMap + reachSize */ | ||
| if (unlikely(limex_len < reach_prefix_end)) { | ||
| DEBUG_PRINTF("LimEx[%u] too small for reachMap\n", qi); | ||
| return HS_INVALID; | ||
| } |
Comment on lines
+281
to
+283
| if (!rose->nfaInfoOffset || rose->nfaInfoOffset >= rose_size) { | ||
| return HS_SUCCESS; /* no NFA engines - nothing to check */ | ||
| } |
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.
No description provided.