Skip to content

fix(encodings): decode uuencode lines whose trailing spaces were stripped - #60

Open
VISHNU0906 wants to merge 2 commits into
OWASP:mainfrom
VISHNU0906:fix/uudecode-stripped-trailing-spaces
Open

VISHNU0906 wants to merge 2 commits into
OWASP:mainfrom
VISHNU0906:fix/uudecode-stripped-trailing-spaces

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

What this changes

From UUEncode only decoded complete four-character groups, so a line that lost its trailing characters dropped the bytes they belonged to. That happens a lot in practice: encoders that write a space for zero (Python's binascii.b2a_uu by default) end lines with spaces, and editors or mail clients strip them. Hello encodes as %2&5L;&\ and once the trailing space is gone DecodeBox gave back Hel. The decoder already meant to read a missing character as zero (|| 96), but the loop stopped before it got there. It now keeps going until the line's length byte is satisfied, which matches binascii.a2b_uu.

Related issue

none

How it was tested

New case in operations.verified.test.ts next to the UUencode round trip: %2&5L;&\ and %2&5L;&\ both give Hello, and #0P gives 43 00 00 (same as binascii.a2b_uu). It fails on main.

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


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 (no new strings)
  • Layout / RTL and keyboard checks (no UI change)
  • Malformed and hostile input handled without crashing or hanging the tab

@m4sh-wacker

Copy link
Copy Markdown
Collaborator

One resource-exhaustion issue needs to be addressed before merging.

In fromUuencode(), decoded bytes are accumulated in the out array without checking the engine's MAX_OUTPUT limit (16 MiB).

The size check in bake() happens only after the operation returns. This means the decoder can allocate an oversized output before the existing protection is applied.

For example, a relatively small input containing many _ lines (each declaring 63 output bytes) can exceed the 16 MiB limit and potentially cause excessive memory consumption.

Please:

  1. Enforce the output limit incrementally before decoding or allocating each line. For example, use checkSize(out.length + length) from ../runtime/limits before creating the decoded array.
  2. Add a regression test that verifies inputs exceeding MAX_OUTPUT are rejected with the expected error.
  3. Ensure the limit is enforced before excessive memory allocation, not only after decoding finishes.

Thanks!

@VISHNU0906

VISHNU0906 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for catching that. fromUuencode() now calls checkSize(out.length + length) before it decodes each line, so it stops with the usual "Output exceeds the processing limit" error before the array grows past MAX_OUTPUT. The new test feeds 266,306 _ lines (one line past 16 MiB) straight into the operation's run, so it doesn't rely on the check in bake(), and it fails without the fix. Pushed in efb10fb.

This branch has not been deployed

No deployments
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