-
Notifications
You must be signed in to change notification settings - Fork 656
bug(gmail): get --format raw fails "illegal base64 data" on multipart messages #922
Copy link
Copy link
Closed
Labels
P2Normal priority bug or improvement with limited blast radius.Normal priority bug or improvement with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Metadata
Metadata
Assignees
Labels
P2Normal priority bug or improvement with limited blast radius.Normal priority bug or improvement with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
Summary
gog gmail get <id> --format rawfails on many messages with:It prints the envelope lines (
id/thread_id/label_ids) and then dies, so the rawRFC822 output is never emitted.
--format fulland--format metadatawork on the samemessage — only
rawis affected.Repro
Affected class
Not multipart- or attachment-specific, though larger messages hit it more often by chance.
The Gmail API's
rawfield is padded base64url. Whether it fails depends only on theRFC822 byte length:
=padding → decodes fine=padding chars → failsSo roughly two-thirds of messages fail. In every failing case observed, the reported byte
offset
<N>is exactly the index of the first=padding character (at the very end of thebase64 string). Example: a message with a 91208-char
rawfield failed at byte 91207 — thelone trailing
=.Root cause (v0.34.0)
internal/cmd/gmail_get.go:130decodes the APIrawfield with the unpadded URLencoding:
The Gmail API returns
rawas padded base64url, butbase64.RawURLEncodingis the padding-free variant and rejects the trailing
=as illegal input — hence "illegal base64 data atinput byte " pointing at the padding.
Suggested fix
Use the padded URL encoding:
For robustness against responses that omit padding, normalize first (e.g. strip trailing
=and use
RawURLEncoding, or pad to a multiple of 4 and useURLEncoding). A regression testshould cover a
rawvalue whose decoded length is not a multiple of 3.Environment
gog v0.34.0. Root cause confirmed by reading source at
internal/cmd/gmail_get.go:130.