Fix IndexError on empty single-count field values (#254) - #256
Open
gaoflow wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #254.
Problem
process_filecrashes withIndexError: list index out of rangeatexif_header.py:241. When a non-ASCII field is declared withcount == 1but decoding produced no value — e.g. a float field whose data is truncated/corrupted, which_process_fielddeliberately skips with aPossibly corrupted fieldwarning —valuesis left empty whilecountis still1._get_printable_for_fieldthen doesstr(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 FLOAT64count=1entry whose value pointer is past EOF, which reproduces the empty-valuespath exactly. The test reads it and assertsprintable == "". Without the fix it raises theIndexErrorfrom 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.