Skip to content

Commit

Permalink
fix: read exactly 8 bytes even when receiving whole file
Browse files Browse the repository at this point in the history
  • Loading branch information
scabala committed Oct 24, 2024
1 parent 26e70c9 commit 451ea03
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions libvirt/volume_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,17 @@ func (i *httpImage) IsQCOW2() (bool, error) {
response.Status)
}

header, err := io.ReadAll(response.Body)
header := make([]byte, 8)
n, err := io.ReadFull(response.Body, header)
if err != nil {
return false, err
}

if len(header) < 8 {
if n < 8 {
return false, fmt.Errorf(
"can't retrieve read header of resource to determine file type: %s - %d bytes read",
i.url.String(),
len(header))
n)
}

return isQCOW2Header(header)
Expand Down

0 comments on commit 451ea03

Please sign in to comment.