Skip to content

Fix IndexError on empty single-count field values (#254) - #256

Open
gaoflow wants to merge 1 commit into
ianare:masterfrom
gaoflow:fix/254-empty-float-value-indexerror
Open

Fix IndexError on empty single-count field values (#254)#256
gaoflow wants to merge 1 commit into
ianare:masterfrom
gaoflow:fix/254-empty-float-value-indexerror

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 17, 2026

Copy link
Copy Markdown

Fixes #254.

Problem

process_file crashes with IndexError: list index out of range at exif_header.py:241. When a non-ASCII field is declared with count == 1 but decoding produced no value — e.g. a float field whose data is truncated/corrupted, which _process_field deliberately skips with a Possibly corrupted field warning — values is left empty while count is still 1. _get_printable_for_field then does str(values[0]) on the empty list and raises, aborting the whole read (this is the path hit by some DJI MakerNote blocks, per the issue).

Fix

Guard the index: use str(values[0]) if values else "", matching the conservative empty-string behavior already used on the ASCII path. This is the fix suggested in the issue.

Test

@ianare asked for a sample to regress against. Rather than a proprietary DJI image, I added a synthetic 26-byte little-endian TIFF fixture (tests/resources/tiff/empty_float_value.tiff) with one FLOAT64 count=1 entry whose value pointer is past EOF, which reproduces the empty-values path exactly. The test reads it and asserts printable == "". Without the fix it raises the IndexError from the issue; with it the full suite passes (32).

Disclosure: I used AI assistance (Claude) to help locate and draft this fix, under my direction and review.

When a non-ASCII field is declared with count 1 but decoding produced no
value (e.g. a float field whose data is truncated/corrupted, which
_process_field skips with a 'Possibly corrupted field' warning),
_get_printable_for_field did str(values[0]) on an empty list and raised
IndexError, aborting the whole process_file call. Guard the index and fall
back to an empty string, matching the conservative behavior of the ASCII path.

Adds a synthetic 26-byte TIFF fixture reproducing the empty-value path and a
regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError in ExifHeader._get_printable_for_field on empty MakerNote values list (DJI M3E)

1 participant