Skip to content

fix(encodings): refuse Base45 and Base85 groups that overflow - #50

Merged
m4sh-wacker merged 2 commits into
OWASP:mainfrom
VISHNU0906:fix/base45-base85-group-range
Dec 1, 2026
Merged

m4sh-wacker merged 2 commits into
OWASP:mainfrom
VISHNU0906:fix/base45-base85-group-range

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

What this changes

From Base45 checks that a three-digit group fits in two bytes, but a two-digit group was pushed as is, so ZZ (1610) silently came out as the byte 0x4a (RFC 9285 says a two-digit group above 255 is invalid). From Base85 had no range check at all, so s8W-" (2^32) decoded to 00 00 00 00 and uuuuu to arbitrary bytes. Both decoders now raise the same "group is out of range" error instead of wrapping the value. Full and padded final Base85 groups are checked, for every alphabet.

Related issue

none

How it was tested

New cases in operations.verified.test.ts next to the other Base45 edge cases: the largest valid groups still decode (U5 to ff, s8W-! to ffffffff), and ZZ, BB8::, s8W-", uuuuu, uuu and Z85 %%%%% are refused. Both tests fail on main.

Locally on Node 24 and Node 22: npm run lint, npm run typecheck, npm run test -- --run (1271 passed), npm run build and npm run check:sdk-dist, plus the CI Chrome load check and the GraalJS Java provider checks.


Checklist

  • npm run lint, npm run typecheck, npm run test and npm run build all pass locally
  • Tests added or updated, including a case that would have failed before this change
  • No any introduced in application code
  • No eval, new Function, dangerouslySetInnerHTML, or innerHTML assignment
  • No new runtime dependency (or it was discussed in an issue first, linked above)
  • User-facing strings go through the i18n map (engine error text only, no UI change)
  • Layout / RTL and keyboard checks (no UI change)
  • Malformed and hostile input handled without crashing or hanging the tab

From Base45 checked the range of a three-digit group but not a two-digit
one, so 'ZZ' (1610) came out as the single byte 0x4a. From Base85 never
checked its groups, so 's8W-"' (2^32) decoded to four zero bytes and
'uuuuu' to arbitrary bytes. Both now raise the same out-of-range error
instead of wrapping the value.
@m4sh-wacker

Copy link
Copy Markdown
Collaborator

Thank you for your contribution and for taking the time to improve DecodeBox. Really appreciate your work!

@m4sh-wacker
m4sh-wacker merged commit 9a22db1 into OWASP:main Dec 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants