ValveSoftware / ValveSoftware/GameNetworkingSockets
Potential integer overflow in Base64 decode size calculation (DecodeBase64ToBuf)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 9.9k
- Forks
- 749
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 1
Description
Description
In DecodeBase64ToBuf(), the buffer size for Base64 decoding is calculated as:
uint32 cubDecodeSize = cbEncoded * 3 / 4 + 1;
This calculation could potentially overflow if cbEncoded ever exceeds 0x55555555. While this is currently mitigated by input size limits (e.g., certificate size is capped at 4096 bytes), adding a defensive check would improve code robustness.
Proof of Concept
uint32 cbEncoded = 0xAAAAAAAA;
uint32 cubDecodeSize = cbEncoded * 3 / 4 + 1;
// Result: 0x40000000 (1 GB)
Suggested Improvement
To prevent potential issues if input size limits change in the future:
if ( cbEncoded > 0x55555555 ) {
return false;
}
uint32 cubDecodeSize = cbEncoded * 3 / 4 + 1;
Severity
Low — Not currently exploitable due to existing input size restrictions.
Suggested as a defense-in-depth hardening measure.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DecodeBase64ToBuf() and inspect how cbEncoded is obtained and how existing input limits constrain it. Add the defensive oversized-input handling described in the issue, then verify that oversized values are rejected without arithmetic overflow and that normal Base64 decoding remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 74/100