mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-02-02 11:34:20 +02:00
Fix decoding BMP with unusual offset
This commit is contained in:
parent
fc35aaa2fd
commit
de44e11182
@ -1,6 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Fix
|
||||||
|
- Fix support of BMP with unusual data offsets.
|
||||||
|
|
||||||
## [3.2.0] - 2022-01-18
|
## [3.2.0] - 2022-01-18
|
||||||
### Added
|
### Added
|
||||||
|
20
vips/bmp.go
20
vips/bmp.go
@ -259,10 +259,6 @@ func (img *Image) loadBmp(data []byte) error {
|
|||||||
case 1, 2, 4, 8:
|
case 1, 2, 4, 8:
|
||||||
palColors := readUint32(b[46:50])
|
palColors := readUint32(b[46:50])
|
||||||
|
|
||||||
if offset != fileHeaderLen+infoLen+palColors*4 {
|
|
||||||
return errBmpUnsupported
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := io.ReadFull(r, b[:palColors*4])
|
_, err := io.ReadFull(r, b[:palColors*4])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -275,23 +271,27 @@ func (img *Image) loadBmp(data []byte) error {
|
|||||||
palette[i] = Color{b[4*i+2], b[4*i+1], b[4*i+0]}
|
palette[i] = Color{b[4*i+2], b[4*i+1], b[4*i+0]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := r.Seek(int64(offset), io.SeekStart); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return img.decodeBmpPaletted(r, width, height, int(bpp), palette, topDown)
|
return img.decodeBmpPaletted(r, width, height, int(bpp), palette, topDown)
|
||||||
case 24:
|
case 24:
|
||||||
if offset != fileHeaderLen+infoLen {
|
if _, err := r.Seek(int64(offset), io.SeekStart); err != nil {
|
||||||
return errBmpUnsupported
|
return err
|
||||||
}
|
}
|
||||||
return img.decodeBmpRGB(r, width, height, 3, topDown, true)
|
return img.decodeBmpRGB(r, width, height, 3, topDown, true)
|
||||||
case 32:
|
case 32:
|
||||||
if offset != fileHeaderLen+infoLen {
|
|
||||||
return errBmpUnsupported
|
|
||||||
}
|
|
||||||
|
|
||||||
noAlpha := true
|
noAlpha := true
|
||||||
if infoLen >= 70 {
|
if infoLen >= 70 {
|
||||||
// Alpha mask is empty, so no alpha here
|
// Alpha mask is empty, so no alpha here
|
||||||
noAlpha = readUint32(b[66:70]) == 0
|
noAlpha = readUint32(b[66:70]) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := r.Seek(int64(offset), io.SeekStart); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return img.decodeBmpRGB(r, width, height, 4, topDown, noAlpha)
|
return img.decodeBmpRGB(r, width, height, 4, topDown, noAlpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user