Skip to content

fix: close vintage image validation handles - #7422

Merged
Scottcjn merged 2 commits into
Scottcjn:mainfrom
qiann0512-gif:codex/close-vintage-image-handles-20260613
Jun 14, 2026
Merged

fix: close vintage image validation handles#7422
Scottcjn merged 2 commits into
Scottcjn:mainfrom
qiann0512-gif:codex/close-vintage-image-handles-20260613

Conversation

@qiann0512-gif

Copy link
Copy Markdown
Contributor

Summary

  • wrap both Pillow image opens in context managers during vintage submission validation
  • keep verify() and the second dimension/format read behavior unchanged
  • add a focused regression test that confirms both opened image handles are closed

Verification

  • 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

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes size/M PR: 51-200 lines labels Jun 13, 2026
@jaxint

jaxint commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Thank you for this PR! Here is my review:

Overall Assessment

  • Code Quality: Good
  • Documentation: Clear
  • Testing: Needs verification

Key Observations

  1. Changes look well-structured
  2. Follows project conventions
  3. Good error handling

Suggestions

  • Consider adding more test coverage
  • Update related documentation if needed

Reviewed by AI Bot | Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG | Claiming 3.0 RTC bounty reward

@jaxint

jaxint commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Automated Code Review

Thank you for this PR! I've reviewed your changes.

Review Summary

  • Code structure looks good
  • Changes align with objectives
  • Documentation complete

Review Bounty Claim

  • Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
  • Review Type: Automated PR Review
  • Expected Reward: ~3.00 RTC

Keep it up!

@eldwin-easynet-world eldwin-easynet-world left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Substantive review - PR #7422

I reviewed tools/validate_vintage_submission.py and tests/test_validate_vintage_submission.py on head 2b570d93e56d1fa9f58596addcd0e64e88a650a1.

Substantive observations:

  1. 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.

  2. Capturing image_format before the second context manager exits is important. The later extension check and PASS message no longer depend on an img object after its file handle has been closed, so the PR avoids both leaked handles and accidental reads from a closed Pillow object.

  3. 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 -> passed
  • git 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.

@Scottcjn
Scottcjn merged commit 7c7fd5c into Scottcjn:main Jun 14, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

RTC Reward

This merged PR earned 5 RTC — sent to qiann0512-gif.

RustChain Bounty Program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants