@@ -184,10 +184,13 @@ func (x CompressionType) MarshalText() ([]byte, error) {
184
184
return []byte (x .String ()), nil
185
185
}
186
186
187
- type Decompressor func (r io.Reader ) io.ReadCloser
187
+ type Decompressor func (r io.Reader ) ( io.ReadCloser , error )
188
188
189
189
var decompressors = map [CompressionType ]Decompressor {
190
- CompressionTypeZlib : flate .NewReader , // no zlib header
190
+ // no zlib header
191
+ CompressionTypeZlib : func (r io.Reader ) (io.ReadCloser , error ) {
192
+ return flate .NewReader (r ), nil
193
+ },
191
194
}
192
195
193
196
// SetDecompressor sets a custom decompressor.
@@ -749,7 +752,10 @@ func (img *Qcow2) readAtAlignedCompressed(p []byte, off int64, desc compressedCl
749
752
additionalSectors := desc .additionalSectors (int (img .Header .ClusterBits ))
750
753
compressedSize := img .clusterSize + 512 * additionalSectors
751
754
compressedSR := io .NewSectionReader (img .ra , int64 (hostClusterOffset ), int64 (compressedSize ))
752
- zr := img .decompressor (compressedSR )
755
+ zr , err := img .decompressor (compressedSR )
756
+ if err != nil {
757
+ return 0 , fmt .Errorf ("could not open the decompressor: %w" , err )
758
+ }
753
759
defer zr .Close ()
754
760
if discard := off % int64 (img .clusterSize ); discard != 0 {
755
761
if _ , err := io .CopyN (io .Discard , zr , discard ); err != nil {
0 commit comments