golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124k stars 17.67k forks source link

encoding/base64: ignore \r \n during decode #2541

Closed gopherbot closed 9 years ago

gopherbot commented 12 years ago

by jason.swank:

The base64 package does not decode base64 encoded content with newlines, as is typical
w/ email attachments and most base64 implementations every 76 characters.

The Mime RFC (2045) section 6.8 specifies all non-alphanumeric characters must be
ignored by a compliant decoder, but warnings/errors might be appropriate under some
circumstances.

Attached is a small go base64 program- base64.go.  Using it along w/ the system's base64
command, it is easy to reproduce the issue:

1) WORKS, no newlines: 
   $ echo -n "Hello, World" | base64 -w 0 | ./base64-go
   Hello, World

2) BROKEN, newlines every 12 characters:
   $ echo -n "Hello, World" | base64 -w 12 | ./base64-go
   Hello, Wo
   illegal base64 data at input byte 12

Which compiler are you using (5g, 6g, 8g, gccgo)? 8g

Which operating system are you using? Linux i686

Which revision are you using?  0beb796b4ef8+ weekly/weekly.2011-12-02

Please provide any additional information below.

Attachments:

  1. base64-go.go (407 bytes)
rsc commented 12 years ago

Comment 1:

Labels changed: added priority-later, removed priority-medium.

rsc commented 12 years ago

Comment 2:

Labels changed: added priority-go1.

robpike commented 12 years ago

Comment 3:

Owner changed to @robpike.

Status changed to Accepted.

robpike commented 12 years ago

Comment 4:

assigning to brad, cc to adam. i honestly do not understand what the correct behavior
should be. encoding is particularly unclear.

Owner changed to @bradfitz.

agl commented 12 years ago

Comment 5:

FWIW, I think I agree that newlines should be ignored in decoding - they certainly are
in Python. I'll fix this unless someone beats me to it.
robpike commented 12 years ago

Comment 6:

Owner changed to builder@golang.org.

rsc commented 12 years ago

Comment 8:

Labels changed: added go1-must.

dsymonds commented 12 years ago

Comment 9:

Owner changed to @dsymonds.

dsymonds commented 12 years ago

Comment 10:

Status changed to Started.

dsymonds commented 12 years ago

Comment 11:

This issue was closed by revision 2f2b6e55ef69126bef77396a3834915b2121fa8.

Status changed to Fixed.