Skip to content

Commit

Permalink
Ensure that symlink names are completely read
Browse files Browse the repository at this point in the history
A single Read(buf) from the payload does not necessarily read the whole
content of the payload. Use ioutil.ReadAll() to ensure that we always
read the whole symlink name.

Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Jan 27, 2021
1 parent 10fedd5 commit debad0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/rpm/cpio2tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"archive/tar"
"fmt"
"io"
"io/ioutil"
"time"

"github.com/sassoftware/go-rpmutils/cpio"
Expand Down Expand Up @@ -98,8 +99,8 @@ func Tar(rs io.Reader, tarfile *tar.Writer, noSymlinksAndDirs bool, capabilities
continue
}
tarHeader.Typeflag = tar.TypeSymlink
buf := make([]byte, entry.Header.Filesize())
if _, err := entry.Payload.Read(buf); err != nil {
buf, err := ioutil.ReadAll(entry.Payload)
if err != nil {
return err
}
tarHeader.Linkname = string(buf)
Expand Down
5 changes: 3 additions & 2 deletions pkg/rpm/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -207,8 +208,8 @@ func CPIOToTarHeader(entry *cpio.CpioEntry) (*tar.Header, error) {
tarHeader.Typeflag = tar.TypeFifo
case cpio.S_ISLNK:
tarHeader.Typeflag = tar.TypeSymlink
buf := make([]byte, entry.Header.Filesize())
if _, err := entry.Payload.Read(buf); err != nil {
buf, err := ioutil.ReadAll(entry.Payload)
if err != nil {
return nil, err
}
tarHeader.Linkname = string(buf)
Expand Down

0 comments on commit debad0c

Please sign in to comment.