• Joe Tsai's avatar
    archive/tar: detect truncated files · e3b615fd
    Joe Tsai authored
    Motivation:
    * Reader.skipUnread never reports io.ErrUnexpectedEOF. This is strange
    given that io.ErrUnexpectedEOF is given through Reader.Read if the
    user manually reads the file.
    * Reader.skipUnread fails to detect truncated files since io.Seeker
    is lazy about reporting errors. Thus, the behavior of Reader differs
    whether the input io.Reader also satisfies io.Seeker or not.
    
    To solve this, we seek to one before the end of the data section and
    always rely on at least one call to io.CopyN. If the tr.r satisfies
    io.Seeker, this is guarunteed to never read more than blockSize.
    
    Fixes #12557
    
    Change-Id: I0ddddfc6bed0d74465cb7e7a02b26f1de7a7a279
    Reviewed-on: https://go-review.googlesource.com/15175Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    e3b615fd
reader.go 26.2 KB