Security Fixes - #475
Open
keerthimuvva52 wants to merge 2 commits into
Open
Conversation
keerthimuvva52
requested review from
DetiPrudvi08,
alexanderintc,
Copilot,
nirint and
shubhangi-shrivastava
July 21, 2026 06:21
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.
This PR adds defenses against malformed/forged serialized databases by validating critical engine offsets and IDs during database load, and by hardening runtime dispatch in FDR execution.
Changes:
- Added
FDR_ENGINE_COUNTto define the valid range for serialized FDRengineIDvalues. - Added runtime bounds/null checks around FDR dispatch table indexing in
fdrExecandfdrExecStreaming. - Added multiple database-load validation passes for mcsheng successor tables, FDR engine IDs, Tamarama subengine offsets, and LimEx reach map values.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/fdr/fdr.h | Introduces a shared constant for the FDR dispatch-table size used by validation code. |
| src/fdr/fdr.c | Adds defensive checks to prevent out-of-bounds/NULL dispatch function calls from forged engineID. |
| src/database.c | Adds database integrity validations to reject serialized databases that could trigger OOB reads at scan time. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+633
to
+672
| 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); | ||
|
|
||
| /* 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; | ||
| } | ||
|
|
||
| const struct LimExNFA32 *limex = | ||
| (const struct LimExNFA32 *)limex_base; | ||
| const u32 reachSize = limex->reachSize; | ||
|
|
||
| if (unlikely(reachSize == 0)) { | ||
| DEBUG_PRINTF("LimEx[%u] reachSize is zero\n", qi); | ||
| return HS_INVALID; | ||
| } | ||
|
|
||
| /* Validate every reachMap entry is within bounds. */ | ||
| for (u32 i = 0; i < N_CHARS; i++) { | ||
| if (unlikely(limex->reachMap[i] >= reachSize)) { | ||
| DEBUG_PRINTF("LimEx[%u] reachMap[%u]=%u >= reachSize=%u\n", | ||
| qi, i, limex->reachMap[i], reachSize); | ||
| return HS_INVALID; | ||
| } | ||
| } |
Comment on lines
+369
to
+371
|
|
||
| u32 as = m->alphaShift; | ||
| u32 alpha_size = 1U << as; |
Comment on lines
+584
to
+591
| /* Verify child NFA body fits within the Tamarama image */ | ||
| const struct NFA *child = | ||
| (const struct NFA *)(tama_base + child_off); | ||
| if (unlikely(child_off + child->length > tama_len)) { | ||
| DEBUG_PRINTF("Tamarama[%u] sub[%u] child body overflows\n", | ||
| qi, i); | ||
| return HS_INVALID; | ||
| } |
Comment on lines
+848
to
853
| assert(fdr->engineID < ARRAY_LENGTH(funcs)); | ||
| if (unlikely(fdr->engineID >= ARRAY_LENGTH(funcs)) || !funcs[fdr->engineID]) { | ||
| return HWLM_SUCCESS; /* reject: forged engineID */ | ||
| } | ||
| assert(funcs[fdr->engineID]); | ||
| return funcs[fdr->engineID](fdr, &a, groups); |
Comment on lines
+39
to
+41
| /** Number of entries in the fdrExec dispatch table (funcs[]). Any serialized | ||
| * FDR engineID must be strictly less than this value. */ | ||
| #define FDR_ENGINE_COUNT 19 |
Comment on lines
+905
to
+914
| /* Validate LimEx NFA reachMap entries (CWE-125). */ | ||
| if (unlikely(db_validate_limex_reach_map(rose, rose_size) != HS_SUCCESS)) { | ||
| DEBUG_PRINTF("LimEx reachMap validation failed\n"); | ||
| return HS_INVALID; | ||
| } | ||
| /* Validate Tamarama subengine offsets (CWE-125). */ | ||
| if (unlikely(db_validate_tamarama_offsets(rose, rose_size) != HS_SUCCESS)) { | ||
| DEBUG_PRINTF("Tamarama subengine offset validation failed\n"); | ||
| return HS_INVALID; | ||
| } |
keerthimuvva52
force-pushed
the
outbound_fixes
branch
from
July 24, 2026 09:26
5fa85dc to
5c43a69
Compare
keerthimuvva52
force-pushed
the
outbound_fixes
branch
from
July 24, 2026 09:36
0904e02 to
6aadd39
Compare
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.