ifd_enumerate: Bugfix for incorrect read semantics.

- ...to make sure we get the right number of bytes.
This commit is contained in:
Dustin Oprea 2018-09-16 03:42:48 -04:00
parent 811286316f
commit ab09051aaa

View File

@ -57,11 +57,17 @@ func (ife *IfdTagEnumerator) getUint16() (value uint16, raw []byte, err error) {
} }
}() }()
raw = make([]byte, 2) needBytes := 2
offset := 0
raw = make([]byte, needBytes)
_, err = ife.buffer.Read(raw) for offset < needBytes {
n, err := ife.buffer.Read(raw[offset:])
log.PanicIf(err) log.PanicIf(err)
offset += n
}
if ife.byteOrder == binary.BigEndian { if ife.byteOrder == binary.BigEndian {
value = binary.BigEndian.Uint16(raw) value = binary.BigEndian.Uint16(raw)
} else { } else {
@ -81,11 +87,17 @@ func (ife *IfdTagEnumerator) getUint32() (value uint32, raw []byte, err error) {
} }
}() }()
raw = make([]byte, 4) needBytes := 4
offset := 0
raw = make([]byte, needBytes)
_, err = ife.buffer.Read(raw) for offset < needBytes {
n, err := ife.buffer.Read(raw[offset:])
log.PanicIf(err) log.PanicIf(err)
offset += n
}
if ife.byteOrder == binary.BigEndian { if ife.byteOrder == binary.BigEndian {
value = binary.BigEndian.Uint32(raw) value = binary.BigEndian.Uint32(raw)
} else { } else {