Fix potential quint32 wrap in KDB 1 importer - #13682
Merged
Merged
Conversation
parseGroupTreeState() retrieves the number of record tree states from a 32-bit integer. It then calculates the number of bytes to read as num * 5, which is checked against the actual buffer length. The multiplication occurs as quint32, which wraps at 2^32. An attacker could craft a 32-bit value that wraps to match the observed buffer length. The following loop, however, uses num directly and may thus loop millions of times, reading beyond the end of the buffer. No bytes are written and the minimum number that wraps is 2^32 / 5, which is well beyond any reasonable buffer size. Hence this is exploitable only as a denial of service. Given that this requires a crafted KDB file, there are easier ways to make the contents of a file unreadable.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Add regression coverage for the malformed count that triggered the wraparound.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This pull request hardens KeePass 1 group-tree-state parsing against 32-bit multiplication overflow.
Changes:
- Performs record-size arithmetic using
quint64. - Rejects malformed metastream lengths before iteration.
File summaries
| File | Summary |
|---|---|
src/format/KeePass1Reader.cpp |
Uses 64-bit arithmetic for record-size validation. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #13682 +/- ##
========================================
Coverage 63.14% 63.14%
========================================
Files 388 388
Lines 41119 41120 +1
========================================
+ Hits 25963 25964 +1
Misses 15156 15156 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
droidmonkey
approved these changes
Sep 16, 2026
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.
parseGroupTreeState()retrieves the number of record tree states from a 32-bit integer. It then calculates the number of bytes to read asnum * 5, which is checked against the actual buffer length. The multiplication occurs as quint32, which wraps at 2^32. An attacker could craft a 32-bit value that wraps to match the observed buffer length. The following loop, however, usesnumdirectly and may thus loop millions of times, reading beyond the end of the buffer.No bytes are written and the minimum number that wraps is 2^32 / 5, which is well beyond any reasonable buffer size. Hence this is exploitable only as a denial of service. Given that this requires a crafted KDB file, there are easier ways to make the contents of a file unreadable.
Type of change