Repository navigation
Conversation
get_next_sector() rejected only values at or above FREESECT, so ENDOFCHAIN was returned as if it were a sector number and locate_final_sector() kept walking past the end of a chain instead of stopping at it. The tiny resulting FAT sector number, 0xFFFFFFFE divided by the entries per sector, then made get_fat_sector_location() subtract entriesPerSector once per loop iteration for millions of iterations, each resolving another sector. On a 98 KiB file this costs roughly 0.4 seconds in a release build and 1.8 seconds with sanitizers. Malformed MSI input therefore causes unnecessary CPU work during signing and verification. Treat ENDOFCHAIN and the other reserved markers as chain terminators, and reject FAT sector numbers that the header does not account for before the DIFAT walk, which bounds the loop by a validated value rather than by a 32-bit input. read_mini_stream() also looked up a next mini sector after copying the last bytes of a stream, unlike read_stream(); skip that lookup so the stricter terminator check cannot reject valid streams.
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.
Pull Request Type
Related Issue
Issue number: N/A
Current Behavior
Malformed MSI sector chains can treat
ENDOFCHAINas a sector number, causing millions of unnecessary DIFAT-walk iterations during signing or verification.New Behavior
Reject chain terminators and FAT sector numbers outside the header's declared range before walking the chain. Stop reading a mini stream once its requested bytes have been copied, avoiding an unnecessary lookup past its final sector.
Scope of Changes
MSI sector-chain validation and its release note.
Testing
Release build succeeded with GCC 16.2 and OpenSSL 3.6.5. All 29 selected CTest checks passed: the MSI storage-tree tests and HTTP-server setup/cleanup (
ctest -R '^(start_server|stop_server|msi_tree_.*)$' --output-on-failure).License Declaration