ValveSoftware / ValveSoftware/GameNetworkingSockets

Potential integer overflow in Base64 decode size calculation (DecodeBase64ToBuf)

Open Beginner friendly
#434 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.