fix: Fix OOM crash in SettingsSerializer readStream() VInt decoder.#707
Open
lggcs wants to merge 2 commits into
Open
fix: Fix OOM crash in SettingsSerializer readStream() VInt decoder.#707lggcs wants to merge 2 commits into
lggcs wants to merge 2 commits into
Conversation
readStream() had no bounds check on the VInt shift count or the accumulated size value before calling QByteArray::resize(), allowing a crafted settings file to trigger an unbounded allocation (up to 2GB) and immediate OOM crash. The signed left-shift also produced undefined behavior when the shift exceeded 28 bits. Add the same overflow guard used by dataToVInt() (num2 > sizeof(int) * CHAR_BIT), stream error status checks, and a post-loop validity check on the decoded size before allocation.
|
Tip Preview URL: |
iphydf
approved these changes
Apr 19, 2026
Member
iphydf
left a comment
There was a problem hiding this comment.
If there's an easy way to unit test this, please add a test. If not, file an issue and I'll follow up.
…tion Covers the three guards added to readStream(): - OOM payload: VInt encoding 0x7FFFFFFF triggers the shift-count guard (num2 > sizeof(int)*CHAR_BIT), preventing QByteArray::resize(INT_MAX) - Shift overflow: 5 continuation bytes push shifts past 32 bits, exercising the same guard for the UB case - Truncated stream: premature EOF is caught by the QDataStream status check before each readRawData - Zero-size VInt: the post-loop num <= 0 guard rejects empty values - Valid settings: round-trips a key/value pair through the serializer - isSerializedFormat: verifies QTOX magic detection
Author
@iphydf comprehensive test case was committed. |
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.
readStream() had no bounds check on the VInt shift count or the accumulated size value before calling QByteArray::resize(), allowing a crafted settings file to trigger an unbounded allocation (up to 2GB) and immediate OOM crash. The signed left-shift also produced undefined behavior when the shift exceeded 28 bits. Add the same overflow guard used by dataToVInt() (num2 > sizeof(int) * CHAR_BIT), stream error status checks, and a post-loop validity check on the decoded size before allocation.
Resolves #706
This change is