Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/pem: can't decode encoded message #10980

Closed
dvyukov opened this issue May 28, 2015 · 3 comments
Closed

encoding/pem: can't decode encoded message #10980

dvyukov opened this issue May 28, 2015 · 3 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented May 28, 2015

encoding/pem successfully decodes a message in the following program; but if the message is re-encoded, decoding fails:

package main

import "encoding/pem"

func main() {
    data := []byte("-----BEGIN foo-----\n\n-----END foo-----")
    b, _ := pem.Decode(data)
    if b == nil {
        return
    }
    enc := pem.EncodeToMemory(b)
    b1, _ := pem.Decode(enc)
    if b1 == nil {
        panic("can't decode encoded")
    }
}

Either the first Decode should fail, or the second Decode should succeed.

on commit 6551803

@dvyukov dvyukov added this to the Go1.5 milestone May 28, 2015
@gopherbot
Copy link

CL https://golang.org/cl/10487 mentions this issue.

@osocurioso
Copy link
Contributor

EncodeToMemory produces "-----BEGIN foo-----\n-----END foo-----" (notice the single newline compared to the original input). The pem.Decode function mistakes the line starting with "\n-----END foo-----" for being a header line, and subsequently does not find an END marker for the block.

@gopherbot
Copy link

CL https://golang.org/cl/10516 mentions this issue.

@agl agl closed this as completed in b8c87a1 May 31, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned agl Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants