Offset Bound Check - #472
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:59
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 offset validation for Tamarama subengine data during RoseEngine database deserialization to prevent out-of-bounds reads (CWE-125).
Changes:
- Introduces
db_validate_tamarama_offsets()to validate Tamarama subengine offset tables and child NFA bounds. - Hooks Tamarama validation into
db_validate_rose_offsets()so corrupted databases are rejected earlier.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+290
to
+293
| for (u32 qi = 0; qi < rose->queueCount; qi++) { | ||
| if (unlikely((const char *)(&infos[qi + 1]) > rose_base + rose_size)) { | ||
| return HS_INVALID; | ||
| } |
Comment on lines
+300
to
+302
| if (unlikely(ni->nfaOffset + sizeof(struct NFA) > rose_size)) { | ||
| return HS_INVALID; | ||
| } |
Comment on lines
+311
to
+313
| if (unlikely(ni->nfaOffset + nfa->length > rose_size)) { | ||
| return HS_INVALID; | ||
| } |
Comment on lines
+354
to
+359
| if (unlikely(child_off >= tama_len || | ||
| child_off + sizeof(struct NFA) > tama_len)) { | ||
| DEBUG_PRINTF("Tamarama[%u] sub[%u] offset %u out of bounds " | ||
| "(tama_len=%u)\n", qi, i, child_off, tama_len); | ||
| return HS_INVALID; | ||
| } |
Comment on lines
+364
to
+368
| if (unlikely(child_off + child->length > tama_len)) { | ||
| DEBUG_PRINTF("Tamarama[%u] sub[%u] child body overflows\n", | ||
| qi, i); | ||
| return HS_INVALID; | ||
| } |
| return HS_INVALID; | ||
| } | ||
|
|
||
| const struct Tamarama *t = (const struct Tamarama *)tama_base; |
Comment on lines
+346
to
+349
| /* subOffsets array starts after baseTops */ | ||
| const u32 *subOffsets = | ||
| (const u32 *)(tama_base + sizeof(struct Tamarama) + | ||
| numSub * sizeof(u32)); |
Comment on lines
+282
to
+284
| 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.