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

Improve bounds checking and EOF handling #9

Merged
merged 2 commits into from
Jul 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewManifest(reader *tar.Reader, header *tar.Header) ImageManifest {
size := header.Size
manifestBytes := make([]byte, size)
_, err := reader.Read(manifestBytes)
if err != nil {
if err != nil && err != io.EOF {
panic(err)
}
var m []ImageManifest
Expand All @@ -56,7 +56,11 @@ type Layer struct {
}

func (layer *Layer) Id() string {
id := layer.History.ID[0:25]
rangeBound := 25
if length := len(layer.History.ID); length < 25 {
rangeBound = length
}
id := layer.History.ID[0:rangeBound]
if len(layer.History.Tags) > 0 {
id = "[" + strings.Join(layer.History.Tags, ",") + "]"
}
Expand Down Expand Up @@ -140,7 +144,9 @@ func InitializeData(imageID string) ([]*Layer, []*filetree.FileTree) {
for idx := 0; idx < len(layers); idx++ {
layers[idx] = new(Layer)
layers[idx].History = history[idx]
layers[idx].TarPath = manifest.LayerTarPaths[idx]
if len(manifest.LayerTarPaths) > idx {
layers[idx].TarPath = manifest.LayerTarPaths[idx]
}
}

return layers, trees
Expand Down Expand Up @@ -198,7 +204,7 @@ func getFileList(parentReader *tar.Reader, header *tar.Header) []filetree.FileIn
var tarredBytes = make([]byte, header.Size)

_, err := parentReader.Read(tarredBytes)
if err != nil {
if err != nil && err != io.EOF {
panic(err)
}
reader := bytes.NewReader(tarredBytes)
Expand Down