1
1
mirror of https://github.com/wader/fq.git synced 2024-11-29 23:27:12 +03:00

Merge pull request #255 from wader/icc-profile-align-eof

icc_profile: Correctly clamp align padding on EOF
This commit is contained in:
Mattias Wadman 2022-05-09 13:33:41 +02:00 committed by GitHub
commit 394edd0533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -163,11 +163,11 @@ func iccProfileDecode(d *decode.D, in interface{}) interface{} {
// "All tag data is required to start on a 4-byte boundary (relative to the start of the profile data stream)"
// we can't add this at the start of the element as we don't know how big the previous element in the stream
// was. instead add alignment after if offset+size does not align and to be sure clamp it if outside buffer.
paddingStart := int64(offset) + int64(size)
paddingBytes := (4 - (int64(offset)+int64(size))%4) % 4
paddingBytes = mathextra.MinInt64(paddingBytes, d.Len()-(paddingStart+paddingBytes))
if paddingBytes != 0 {
d.RangeFn(paddingStart*8, paddingBytes*8, func(d *decode.D) {
alignStart := int64(offset) + int64(size)
alignBytes := (4 - (int64(offset)+int64(size))%4) % 4
alignBytes = mathextra.MinInt64(d.Len()/8-alignStart, alignBytes)
if alignBytes != 0 {
d.RangeFn(alignStart*8, alignBytes*8, func(d *decode.D) {
d.FieldRawLen("alignment", d.BitsLeft())
})
}