fix: return three values when a gif cannot be decoded - #18346
Open
linhongyu510 wants to merge 1 commit into
Open
linhongyu510 wants to merge 1 commit into
linhongyu510 wants to merge 1 commit into
Conversation
`check_and_read` returns a 3-tuple from every branch except the one that
handles an unreadable gif, which returned `(None, False)`. Every caller
unpacks three values, e.g. `tools/infer/predict_system.py:212`:
img, flag_gif, flag_pdf = check_and_read(image_file)
so a corrupted gif raised `ValueError: not enough values to unpack
(expected 3, got 2)` in the caller rather than being skipped -- despite this
branch already logging and returning a sentinel so that the caller could move
on. The same 2-value return is reached from predict_rec, predict_cls,
predict_e2e and predict_sr.
The log line in that branch also passed an unformatted `{}` to `logger.info`,
so the output read literally `Cannot read {}. This gif image maybe corrupted.`
and dropped the path, which was the only thing it existed to report.
Added tests covering both, plus a check that non-gif paths keep their current
return value. Reverting this change turns the first two red.
Co-authored-by: Claude <noreply@anthropic.com>
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.
🔗 Related Issue
None — found while reading
ppocr/utils/utility.py.📖 Description
check_and_readreturns a 3-tuple from every branch except one. Whencv2.VideoCapturecannot decode a gif, it returns(None, False):https://github.com/PaddlePaddle/PaddleOCR/blob/main/ppocr/utils/utility.py#L123-L126
Every caller unpacks three values. From
tools/infer/predict_system.py:212:predict_rec.py:892,predict_cls.py:146,predict_e2e.py:161andpredict_sr.py:136do the same withimg, flag, _ =. So a corrupted gif raises in the caller instead of being skipped:That defeats the branch's own intent — it logs a message and returns a sentinel precisely so the caller can move to the next file.
There is a second problem in the same three lines. The log call passes an unformatted
{}:so the output drops the path that was the only thing it existed to report:
Reproduction
Before this change, on
paddlepaddle 3.3.1/ Python 3.12:After:
(None, False, False)matches what the function already returns for a path it does not handle (utility.py:152), so callers treat the corrupted gif the same way they treat any non-gif, non-pdf input.🧪 Tests
Added
tests/ppocr/test_check_and_read.py: one test per bug, plus a check that non-gif and non-pdf paths keep their current return value. That third test does not depend on the fix and stays green on either side of it.The first two are load-bearing — restoring the old two-value return and the unformatted log message turns exactly those red:
With the fix in place:
The 89 errors are pre-existing on this machine and unrelated: they are all in
tests/pipelines/, which downloads model weights this box cannot reach, andtest_iaa_augment.pyneedsalbumentations. I confirmed viagit stashthattests/pipelines/test_table_recognition_v2.pyproduces the identical errors on a clean checkout.✅ Checklist
blackon changed filesAI assistance was used for this change; I reviewed every changed line and ran the commands above locally.