Skip to content

Commit

Permalink
Fix PGET Expected Byte Check
Browse files Browse the repository at this point in the history
Tar files have padding. Verify the end of the file is null and only
error if there is non-null or we haven't matched content-length from
origin.
  • Loading branch information
tempusfrangit committed Dec 3, 2024
1 parent f56ac41 commit 5f80b75
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/extract/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ func TarFile(r *bufio.Reader, destDir string, overwrite bool) error {
return fmt.Errorf("error creating links: %w", err)
}

// Read the rest of the bytes from the archive and verify they are all null bytes
// This is for validation that the byte count is correct
padding := make([]byte, 1024)
for {
n, err := r.Read(padding)
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("error reading padding bytes: %w", err)
}
for _, b := range padding[:n] {
if b != 0x00 {
return fmt.Errorf("unexpected non-null byte in padding: %x", b)
}
}
}

elapsed := time.Since(startTime).Seconds()
logger.Debug().
Str("extractor", "tar").
Expand Down

0 comments on commit 5f80b75

Please sign in to comment.