Mcsheng Bound fix#474
Closed
keerthimuvva52 wants to merge 1 commit into
Closed
Conversation
keerthimuvva52
requested review from
DetiPrudvi08,
alexanderintc,
Copilot,
nirint and
shubhangi-shrivastava
and removed request for
Copilot
July 17, 2026 06:07
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 database integrity validation for McSheng NFAs to prevent out-of-bounds reads when deserializing a database.
Changes:
- Introduces a new validator that walks McSheng 8-bit/16-bit successor tables and verifies next-state indices are within
state_count. - Validates McSheng start states and aux table bounds against the NFA image.
- Hooks the new validation into
db_validate_rose_offsets.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+365
to
+366
| u32 as = m->alphaShift; | ||
| u32 alpha_size = 1U << as; |
Comment on lines
+294
to
+301
| const char *rose_base = (const char *)rose; | ||
| const struct NfaInfo *infos = | ||
| (const struct NfaInfo *)(rose_base + rose->nfaInfoOffset); | ||
|
|
||
| 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
+399
to
+405
| const u16 *succ_table = | ||
| (const u16 *)((const char *)m + sizeof(struct mcsheng)); | ||
|
|
||
| for (u32 s = 0; s < table_states; s++) { | ||
| for (u32 a = 0; a < alpha_size; a++) { | ||
| u16 next = succ_table[s * alpha_size + a]; | ||
| if (unlikely(next >= state_count)) { |
Comment on lines
+394
to
+397
| if (unlikely(succ_table_bytes == 0 || | ||
| succ_table_bytes % entry_bytes != 0)) { | ||
| return HS_INVALID; | ||
| } |
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.