Fix MakerNote tag size overflow issues at read time.
[platform/upstream/libexif.git] / test / extract-parse.sh
1 #!/bin/sh
2 # Compares the parsed EXIF data extracted from test images with the parsed EXIF
3 # data in the original images. This tests that the tag parsing and writing
4 # round-trip produces an EXIF structure with the same meaning as the original.
5 srcdir="${srcdir:-.}"
6 TMPORIGINAL="$(mktemp)"
7 TMPEXTRACTED="$(mktemp)"
8 TMPDATA="$(mktemp)"
9 trap 'rm -f "${TMPORIGINAL}" "${TMPEXTRACTED}" "${TMPDATA}"' 0
10
11 # Remove the file name, which is a harmless difference between the two outputs.
12 # Also delete the size of the MakerNote. Since the MakerNote is parsed
13 # internally and rewritten, it can sometimes have slightly different padding
14 # and therefore slightly different size, which is a semantically meaningless
15 # difference.
16 # FIXME: Not all MakerNote differences are harmless. For example,
17 # olympus_makernote_variant_4.jpg has a huge size difference, probably because
18 # of a parsing bug in libexif. This should be investigated. Ideally, this would
19 # ignore small differences in size but trigger on larger differences.
20 parse_canonicalize () {
21     sed \
22         -e '/^File /d' \
23         -e '/MakerNote (Undefined)$/{N;N;d}'
24 }
25
26 # Ensure that names are untranslated
27 LANG=
28 LANGUAGE=
29 LC_ALL=C
30 export LANG LANGUAGE LC_ALL
31 for fn in "${srcdir}"/testdata/*.jpg ; do
32     ./test-parse "${fn}" | parse_canonicalize > "${TMPORIGINAL}"
33     ./test-extract -o "${TMPDATA}" "${fn}"
34     ./test-parse "${TMPDATA}" | parse_canonicalize > "${TMPEXTRACTED}"
35     if ! diff "${TMPORIGINAL}" "${TMPEXTRACTED}"; then
36         echo Error parsing "$fn"
37         exit 1
38     fi
39 done