Skip to content

Commit

Permalink
util/converter: fix diffID computation
Browse files Browse the repository at this point in the history
The archive reader was not fully consumed on computating the diffID.

Fix issue 4805

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
(cherry picked from commit e315f0e)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Apr 23, 2024
1 parent 00935df commit ecf1c42
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion util/converter/tarconverter/tarconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type HeaderConverter func(*tar.Header)

// NewReader returns a reader that applies headerConverter.
// srcContent is drained until hitting EOF.
// Forked from https://github.com/moby/moby/blob/v24.0.6/pkg/archive/copy.go#L308-L373 .
func NewReader(srcContent io.Reader, headerConverter HeaderConverter) io.ReadCloser {
rebased, w := io.Pipe()
Expand All @@ -21,7 +22,14 @@ func NewReader(srcContent io.Reader, headerConverter HeaderConverter) io.ReadClo
if err == io.EOF {
// Signals end of archive.
rebasedTar.Close()
w.Close()
// drain the reader into io.Discard, until hitting EOF
// https://github.com/moby/buildkit/pull/4807#discussion_r1544621787
_, err = io.Copy(io.Discard, srcContent)
if err != nil {
w.CloseWithError(err)
} else {
w.Close()
}
return
}
if err != nil {
Expand Down

0 comments on commit ecf1c42

Please sign in to comment.