Skip to content

fix(google): reject malformed provider media base64 - #106969

Closed
sunlit-deng wants to merge 4 commits into
openclaw:mainfrom
sunlit-deng:codex/fix-google-provider-base64
Closed

sunlit-deng wants to merge 4 commits into
openclaw:mainfrom
sunlit-deng:codex/fix-google-provider-base64

Conversation

@sunlit-deng

@sunlit-deng sunlit-deng commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Google provider responses could include malformed inline audio or video base64 that Node would decode permissively instead of rejecting.

Why This Change Was Made

Google music, speech, video generation, and Realtime Live audio now share a strict base64 decoder before materializing provider-returned media. The Google-specific decoder accepts both standard base64 and Google ProtoJSON-valid base64url payloads before canonical validation, while inline video bytes reuse the existing generated-video byte cap before decode so oversized payloads fail before allocating the full buffer.

User Impact

Users get a clear provider error for malformed Google media responses without rejecting valid base64url media that Google may return. Realtime Live malformed inline audio is routed through onError without emitting corrupt audio, and operators keep the existing video media cap behavior without permissive base64 decoding.

Evidence

Live Google TTS run through the production buildGoogleSpeechProvider().synthesize() entrypoint; this was captured on the earlier PR head f36b9f96544a6416e51712ee3881e682409df825 before the base64url compatibility follow-up, and the same entrypoint remains covered by focused regression tests on current head 4f77e023235:

$ GEMINI_API_KEY=<redacted> node node_modules/vitest/vitest.mjs run --config test/vitest/vitest.extension-providers.config.ts extensions/google/live-google-tts-proof.test.ts --reporter verbose

=== LIVE GOOGLE TTS PROOF ===
entrypoint=buildGoogleSpeechProvider().synthesize
started_at=2026-07-14T12:47:34.918Z
model=gemini-3.1-flash-tts-preview
voice=Kore
proxy=explicit-redacted
api_key=redacted
ok=true
output_format=wav
file_extension=.wav
audio_bytes=109484
pcm_payload_bytes=109440
wav_header=RIFF/WAVE

The focused tests drive the real exported provider entrypoints — buildGoogleSpeechProvider().synthesize(), buildGoogleMusicGenerationProvider().generateMusic(), buildGoogleVideoGenerationProvider().generateVideo(), and buildGoogleRealtimeVoiceProvider().createBridge() — with crafted valid, malformed, and oversized provider responses; the decodeGoogleProviderBase64 guard runs as real production code on those response paths:

  • Valid path preserved: legitimate standard base64 and base64url audio/video still materialize; the video byte cap reuses the existing generated-video limit rather than a new arbitrary value, so valid traffic is not truncated.
  • Malformed rejected: music, speech, video, and Google Live malformed inline base64 each raise a provider-specific error instead of decoding corrupt bytes; the Live path does not call onAudio.
  • Oversized rejected before buffering: inline video bytes, direct URI downloads, and SDK file-handle downloads exceeding the media cap fail before unbounded allocation.

Real-trigger-chain run of the production buildGoogleSpeechProvider().synthesize() entrypoint with a crafted TTS response:

=== GOOGLE SPEECH (real buildGoogleSpeechProvider().synthesize) ===
[valid PCM 2048B] synthesize ok=true  decoded audio bytes=2092
[malformed] rejected: Google TTS response returned malformed audio base64
[base64url] synthesize ok=true  decoded pcm payload bytes=4
$ node scripts/run-vitest.mjs extensions/google/realtime-voice-provider.test.ts extensions/google/music-generation-provider.test.ts extensions/google/speech-provider.test.ts extensions/google/video-generation-provider.test.ts
[test] starting test/vitest/vitest.extension-providers.config.ts

 RUN  v4.1.9 <repo root>

 Test Files  4 passed (4)
      Tests  98 passed (98)

[test] passed 1 Vitest shard

CI notes:

  • Rebased onto latest origin/main. The earlier check-dependencies failure flagged an unused export (CurrentUserTimestampOverride) in src/agents/embedded-agent-runner/run/attempt-session-boundary.ts, a file this PR never touches; it was a stale-base artifact and clears after the rebase.
  • Fixed the check-lint oxlint(curly) error by adding braces to the guard in extensions/google/speech-provider.ts.
Focused reproduction commands
PNPM_CONFIG_MINIMUM_RELEASE_AGE=0 PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN=false \
  node scripts/run-vitest.mjs \
  extensions/google/realtime-voice-provider.test.ts \
  extensions/google/music-generation-provider.test.ts \
  extensions/google/speech-provider.test.ts \
  extensions/google/video-generation-provider.test.ts

PNPM_CONFIG_MINIMUM_RELEASE_AGE=0 PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN=false \
  OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 \
  node scripts/check-changed.mjs -- \
  extensions/google/base64.ts \
  extensions/google/realtime-voice-provider.ts \
  extensions/google/realtime-voice-provider.test.ts \
  extensions/google/music-generation-provider.ts \
  extensions/google/music-generation-provider.test.ts \
  extensions/google/speech-provider.ts \
  extensions/google/speech-provider.test.ts \
  extensions/google/video-generation-provider.ts \
  extensions/google/video-generation-provider.test.ts

AI-assisted: built with Codex

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 14, 2026
@clawsweeper

clawsweeper Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 10:32 PM ET / July 28, 2026, 02:32 UTC.

ClawSweeper review

What this changes

This PR adds a Google-plugin-local strict base64 decoder for music, TTS, generated video, and Live voice media, accepting valid base64url while rejecting malformed payloads before media is materialized.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this PR open for normal maintainer merge review: current main still sends Google Live inline audio through permissive Buffer.from(..., "base64"), so the central malformed-media problem remains. The prior Realtime Live comment-restoration blocker is resolved at the current head. Likely related people: scoootscooob is the strongest available routing candidate for the Google realtime-voice path, with medium confidence.

Priority: P2
Reviewed head: 4fe1b217d729b8d352b24d0ee4a950718a2dc881

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused provider-boundary fix with real provider-path evidence, regression coverage across all changed media paths, and no remaining actionable review finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body includes a redacted live Google TTS run through the production provider entrypoint plus focused current-head entrypoint coverage for malformed and base64url paths; the latest commit only restores documentation comments. Private values in any future proof should remain redacted.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes a redacted live Google TTS run through the production provider entrypoint plus focused current-head entrypoint coverage for malformed and base64url paths; the latest commit only restores documentation comments. Private values in any future proof should remain redacted.
Evidence reviewed 5 items Current-main gap: Current main still decodes Google Live inlineData.data with Buffer.from(part.inlineData.data, "base64") in the realtime bridge, so malformed server media can be permissively decoded before it reaches output conversion.
Narrow plugin-boundary implementation: The branch adds a Google-local helper that normalizes the Google-supported base64url alphabet, applies the shared canonical validator, and enforces the existing video byte cap before decoding. The bundled-plugin boundary permits own-local helpers and focused Plugin SDK imports.
Caller coverage: The branch routes Google music generation, Gemini TTS, generated video, and Google Live audio through the same decoder and adds focused valid-base64url and malformed-input coverage for each provider entrypoint.
Findings None None.
Security None None.

How this fits together

The bundled Google plugin receives inline media from Google generation and realtime APIs, converts it into buffers, and returns audio/video to OpenClaw’s media and voice-call flows. This change validates provider-returned encoded bytes at that plugin boundary before downstream playback, transcoding, or file output.

flowchart LR
  A[Google provider response] --> B[Google plugin media paths]
  B --> C[Strict base64 validation]
  C --> D{Valid encoded media?}
  D -->|Yes| E[Decode audio or video buffer]
  E --> F[Playback, transcoding, or generated media output]
  D -->|No| G[Provider error without corrupt media]
Loading

Before merge

  • Complete next step (P2) - No repair queue is needed: the prior actionable comment-restoration finding is fixed and no new mechanical defect was found; this PR is ready for ordinary maintainer merge judgment.
Agent review details

Security

None.

PR surface

Source +26, Tests +207. Total +233 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 76 50 +26
Tests 4 213 6 +207
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 289 56 +233

Review metrics

None.

Technical review

Best possible solution:

Merge the focused Google-plugin decoder after ordinary maintainer review, retaining the provider-local helper and the malformed/base64url regression coverage across all four affected media paths.

Do we have a high-confidence way to reproduce the issue?

Yes, source inspection gives a high-confidence reproduction path: send malformed inlineData.data through the current Google Live, music, TTS, or generated-video response paths, where Node’s permissive base64 decode currently accepts damaged input. The branch’s focused tests exercise these real exported provider entrypoints with malformed and base64url fixtures.

Is this the best way to solve the issue?

Yes. A Google-plugin-local decoder is the narrowest maintainable solution because it reuses the shared canonical base64 contract while preserving Google ProtoJSON-compatible base64url input and the existing generated-video size limit.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9bcc44301bcb.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes a redacted live Google TTS run through the production provider entrypoint plus focused current-head entrypoint coverage for malformed and base64url paths; the latest commit only restores documentation comments. Private values in any future proof should remain redacted.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Malformed Google provider media can cause corrupt generated audio or video handling, but the proposed fix is bounded to one optional provider plugin and has focused coverage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes a redacted live Google TTS run through the production provider entrypoint plus focused current-head entrypoint coverage for malformed and base64url paths; the latest commit only restores documentation comments. Private values in any future proof should remain redacted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a redacted live Google TTS run through the production provider entrypoint plus focused current-head entrypoint coverage for malformed and base64url paths; the latest commit only restores documentation comments. Private values in any future proof should remain redacted.

Evidence

What I checked:

  • Current-main gap: Current main still decodes Google Live inlineData.data with Buffer.from(part.inlineData.data, "base64") in the realtime bridge, so malformed server media can be permissively decoded before it reaches output conversion. (extensions/google/realtime-voice-provider.ts:797, 9bcc44301bcb)
  • Narrow plugin-boundary implementation: The branch adds a Google-local helper that normalizes the Google-supported base64url alphabet, applies the shared canonical validator, and enforces the existing video byte cap before decoding. The bundled-plugin boundary permits own-local helpers and focused Plugin SDK imports. (extensions/google/base64.ts:4, 4fe1b217d729)
  • Caller coverage: The branch routes Google music generation, Gemini TTS, generated video, and Google Live audio through the same decoder and adds focused valid-base64url and malformed-input coverage for each provider entrypoint. (extensions/google/realtime-voice-provider.test.ts:1125, 4fe1b217d729)
  • Prior review continuity: The final branch commit restores the three Realtime Live invariant comments that the prior ClawSweeper review identified; current main shows the protocol-split, parameters, reconnect transcript, and fresh-session transcript-reset invariants retained around the affected bridge. (extensions/google/realtime-voice-provider.ts:220, 4fe1b217d729)
  • Adjacent related work: The linked OpenAI realtime-base64 PR is closed unmerged and affects a separate provider. It is useful as a parallel validation pattern, but it neither implements nor supersedes this Google-plugin fix. (extensions/openai/realtime-voice-provider.ts:1, 8ac745def9d2)

Likely related people:

  • scoootscooob: The release history credits this contributor for the Google Meet/Voice Call work that introduced the realtime Gemini voice bridge, which owns the affected Live-audio output path. (role: feature introducer; confidence: medium; files: extensions/google/realtime-voice-provider.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (35 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-15T00:11:02.978Z sha 70f132869584e3bc51935d1c6867fc3d76dcfba7 :: needs changes before merge. :: [P2] Apply strict decoding to Google Live audio
  • reviewed 2026-07-15T00:28:59.259Z sha 4f77e0232359263f32b13deba20bd34102539b21 :: needs changes before merge. :: [P3] Restore the unrelated Realtime Live invariant comments
  • reviewed 2026-07-16T04:02:23.260Z sha c6ec8117e3ba67654d375622cdd3fb38726651d2 :: needs changes before merge. :: [P3] Restore the Realtime Live invariant comments
  • reviewed 2026-07-16T23:59:20.121Z sha 6a4c0e78ead3e4ed06a462d682e9fa24796a88a6 :: needs changes before merge. :: [P3] Restore the Realtime Live invariant comments
  • reviewed 2026-07-17T14:32:06.081Z sha 98c904d4b55239b63ec8b1cacf4c7db707d715d9 :: needs changes before merge. :: [P3] Restore the Realtime Live invariant comments
  • reviewed 2026-07-25T13:10:40.711Z sha eaba38bccc394ec768c1bd5c1410c85e203093f2 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-27T12:44:09.702Z sha e8d94a51f52abd28e2dd6acda83be52bf9fc119d :: needs changes before merge. :: [P3] Restore the Realtime Live invariant comments
  • reviewed 2026-07-28T01:28:22.678Z sha a29361d :: needs changes before merge. :: [P3] Restore the Realtime Live invariant comments

@sunlit-deng
sunlit-deng force-pushed the codex/fix-google-provider-base64 branch 7 times, most recently from c9043ac to f36b9f9 Compare July 14, 2026 08:03
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 14, 2026
@sunlit-deng

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 14, 2026
@sunlit-deng

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 14, 2026
@sunlit-deng

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 15, 2026
@sunlit-deng
sunlit-deng force-pushed the codex/fix-google-provider-base64 branch 4 times, most recently from 98c904d to da4dc04 Compare July 22, 2026 23:33
@sunlit-deng
sunlit-deng force-pushed the codex/fix-google-provider-base64 branch 3 times, most recently from eaba38b to e8d94a5 Compare July 27, 2026 12:39
@sunlit-deng
sunlit-deng force-pushed the codex/fix-google-provider-base64 branch from e8d94a5 to a29361d Compare July 28, 2026 01:23
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 28, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 28, 2026
@obviyus

obviyus commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Closing as largely superseded — thanks @sunlit-deng, the bug you reported is real and it is fixed on main, just not by this PR.

Malformed base64 is now rejected with a named cause on every Google media path:

  • extensions/google/speech-provider.ts:302 — "Google TTS response returned malformed base64 audio data"
  • extensions/google/realtime-voice-provider.ts:803 — Live stream fails the connection rather than feeding corrupt audio forward
  • extensions/google/video-generation-provider.ts:573
  • src/music-generation/provider-assets.ts:90

That came from a8e52b4 (#114041) for Gemini TTS and 91b1f96 (#114514) for provider binary payloads generally. Before those, a bad payload silently became corrupt audio or video — the outcome your PR was aimed at, and the reason it was worth filing.

One piece of your PR is not on main: accepting base64url-encoded payloads (-/_ instead of +//). Everything else conflicts with the stricter validation that already landed, so rebasing this branch would mostly be reconciling with a fix that duplicates it.

If you want that residual piece, a small PR against current main doing only base64url normalization before the decode — with a case showing a base64url payload that fails today — would be easy to review and I would land it. That is a genuinely separate improvement from rejection, and it is the part nobody else has covered.

Worth being straight about the process failure here: ClawSweeper's review on this PR still describes main as using a bare Buffer.from, which stopped being true when #114041 landed. You had no way to know your fix had been overtaken. Sorry for the wasted cycles.

@sunlit-deng

Copy link
Copy Markdown
Contributor Author

If you want that residual piece, a small PR against current main doing only base64url normalization before the decode — with a case showing a base64url payload that fails today — would be easy to review and I would land it.

Thanks @obviyus — done in #116204.

It is scoped to Google provider base64url normalization only. The PR includes comparable proof through buildGoogleSpeechProvider().synthesize(): the same ProtoJSON-valid base64url payload is rejected on the pinned base and accepted on the PR head, while the mixed-alphabet negative control remains rejected. Focused coverage also exercises music, TTS, video, and Live voice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: google P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants