fix: close vintage image validation handles - #7422
Conversation
Code Review SummaryThank you for this PR! Here is my review: Overall Assessment
Key Observations
Suggestions
Reviewed by AI Bot | Wallet: |
Automated Code ReviewThank you for this PR! I've reviewed your changes. Review Summary
Review Bounty Claim
Keep it up! |
eldwin-easynet-world
left a comment
There was a problem hiding this comment.
Substantive review - PR #7422
I reviewed tools/validate_vintage_submission.py and tests/test_validate_vintage_submission.py on head 2b570d93e56d1fa9f58596addcd0e64e88a650a1.
Substantive observations:
-
The two
with Image.open(...)blocks in_validate_image_core()are the right fix for Pillow handle lifetime.verify()intentionally invalidates the image object, so keeping the verify pass and the metadata pass as two separate context managers closes both file handles while preserving the existing two-pass validation behavior. -
Capturing
image_formatbefore the second context manager exits is important. The later extension check and PASS message no longer depend on animgobject after its file handle has been closed, so the PR avoids both leaked handles and accidental reads from a closed Pillow object. -
The regression test is focused on the resource-management contract instead of implementation trivia: the fake Pillow object records two
__exit__calls, matching the verify reopen pattern. That directly protects the Windows/macOS failure mode where open image files can block cleanup or overwrite.
Validation I ran from a clean temporary checkout:
/tmp/eldwin-rustchain-pr7422-venv/bin/python -m pytest tests/test_validate_vintage_submission.py -q-> 9 passed/tmp/eldwin-rustchain-pr7422-venv/bin/python -m pytest tests/test_validate_vintage_submission.py::test_image_validation_closes_pillow_handles tests/test_validate_vintage_submission.py::test_screenshot_validation_preserves_small_file_warning -q-> 2 passed/tmp/eldwin-rustchain-pr7422-venv/bin/python -m py_compile tools/validate_vintage_submission.py tests/test_validate_vintage_submission.py-> passedgit diff --check origin/main...HEAD-> passed
Why I liked it: it fixes a real cross-platform file-handle footgun with a small, behavior-preserving change and a regression test that exercises the exact close-on-both-opens guarantee.
I received RTC compensation for this review.
RTC RewardThis merged PR earned 5 RTC — sent to |
Summary
verify()and the second dimension/format read behavior unchangedVerification
python -m pytest tests/test_validate_vintage_submission.py(9 passed)python -m py_compile tools/validate_vintage_submission.py tests/test_validate_vintage_submission.py