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 fe0a467
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libvirt/volume_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ 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(),
Expand Down

0 comments on commit fe0a467

Please sign in to comment.