Skip to content

Commit 28996fb

Browse files
Fix corruption issue for FileSource and SceneType headers
This is a hack, a proper fix is needed
1 parent e7f5402 commit 28996fb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

v3/ifd_builder_encode.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,21 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw *
225225
effectiveType = exifcommon.TypeByte
226226
}
227227

228+
// HACK: these two tags of type undefined are represented by
229+
// a single long value, rather than bytes. The code above assumes
230+
// that all undefined tags consist of variable count of bytes.
231+
// This assumption is a problem for these two tags as it results in
232+
// their count field ending up being 4 bytes (a long is 4 bytes) and
233+
// their offset being interpreded as an offset rather than a diredt
234+
// value. As a result 4 longs are being read from an offset from the
235+
// start of the TIFF header and these two tags end up being corrupted,
236+
// which is detected by tools like the `exif` command, which complain
237+
// that these are wrongly sized. This is just a hack to avoid this issue.
238+
// A proper fix is needed
239+
if bt.tagId == 0xa300 || bt.tagId == 0xa301 {
240+
effectiveType = exifcommon.TypeLong
241+
}
242+
228243
// It's a non-unknown value.Calculate the count of values of
229244
// the type that we're writing and the raw bytes for the whole list.
230245

0 commit comments

Comments
 (0)