Repository navigation
fix(schema): validate canonical base64 without a backtracking regex - #51272
darellchua2 wants to merge 1 commit into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
|
Heads-up on the |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #45558
Closes #50336
Type of change
What does this PR do?
In the wild this surfaces as
Error: Schema validation failed ... Prompt.Base64 ... InvalidValuewithPOST /api/session/<id>/prompt http.status=500in the server log.Prompt.Base64used a(?:X{4})*regex, which regex engines evaluate with per-group recursion. Past a few MB the check stops working: on Bun/JSC (the runtime the shipped binary embeds) it silently returnsfalsefor canonical base64, and on V8 it throws RangeError. SincematerializeAttachmentbase64-encodes attachments up to 20 MB, any@-attached file over ~5 MB failedPOST /api/session/:id/promptwith a 500 before reaching the provider.The check is now a length preflight, a single-pass alphabet pattern, and a padding/length consistency test. Canonical base64 always has length ≡ 0 (mod 4), alphabet chars with at most two trailing pads, and 0, 2, or 3 data chars in the final quantum, so accept/reject behavior is unchanged for every input.
How did you verify your code works?
cd packages/schema && bun test— new tests cover the padding edge cases and a 20 MB payload (passes in ~32 ms; the old pattern returnedfalseon it). I also fuzzed 20k mutated canonical strings against the old pattern with zero accept/reject mismatches, checked on Bun 1.4.2 (JSC) and Node 24 (V8).bun run checkpasses.Screenshots / recordings
Not a UI change.
Checklist
Analysis and repro: attachments: dragging file or pasting file path into input fails session setup (Prompt.Base64 500 on /prompt) #45558 (comment)
(The
needs:issuelabel from the bot is stale —Closes #45558/Closes #50336are above; GitHub doesn't record closing references for PRs targeting non-default branches, which is why the GraphQL check comes up empty.)