Skip to content

Fix potential quint32 wrap in KDB 1 importer - #13682

Merged
droidmonkey merged 1 commit into
developfrom
fix/kdb1-importer-integer-wrap
Sep 16, 2026
Merged

droidmonkey merged 1 commit into
developfrom
fix/kdb1-importer-integer-wrap

Conversation

@phoerious

Copy link
Copy Markdown
Member

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.

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

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.
@phoerious phoerious added this to the v2.8.0 milestone Sep 16, 2026
@phoerious
phoerious requested a review from a team September 16, 2026 08:57
Copilot AI lite review requested due to automatic review settings September 16, 2026 08:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread src/format/KeePass1Reader.cpp
@phoerious phoerious changed the title Fixes potential quint32 wrap in KDB 1 importer. Fixe potential quint32 wrap in KDB 1 importer Sep 16, 2026
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.14%. Comparing base (84658ad) to head (745faba).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@droidmonkey
droidmonkey merged commit 5d7f371 into develop Sep 16, 2026
13 checks passed
@droidmonkey
droidmonkey deleted the fix/kdb1-importer-integer-wrap branch September 16, 2026 10:03
@phoerious phoerious changed the title Fixe potential quint32 wrap in KDB 1 importer Fix potential quint32 wrap in KDB 1 importer Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants