Skip to content

fix(screenshots): reject corrupt PNGs during validation - #23161

Open
only21mil wants to merge 2 commits into
pingdotgg:mainfrom
only21mil:r13/a027-reject-corrupt-pngs-during-validation
Open

only21mil wants to merge 2 commits into
pingdotgg:mainfrom
only21mil:r13/a027-reject-corrupt-pngs-during-validation

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

Problem

--validate-only can call a corrupt mobile screenshot "upload-ready". The validator checks dimensions and RGB format using fixed header offsets, but never decodes the image data. A PNG truncated inside IDAT or with a damaged checksum can pass.

On main, --validate-only accepts a PNG truncated to 44 bytes in both the iPhone 6.9-inch and Pixel capture sets. Complete PNGs should pass, and corrupt files should identify the failing asset and exit nonzero.

Change

Decode each asset with the existing PNG.sync.read before returning validation success. Report decoder errors with the asset label and preserve the underlying error as the cause. Keep the original dimension, bit-depth, color-type, alpha, file-size, aspect-ratio and screenshot-count checks. Validation does not rewrite the input.

The focused tests use generated RGB PNGs. They cover an intact file in an offset byte view, metadata-only files, truncation inside IDAT and a damaged IDAT checksum. They exercise real external-format parsing without timers, mocks or devices.

Scope and approval

This fixes an obvious false validation success in existing screenshot tooling, under the contribution guide's exception for a very small, focused bug fix. No prior issue or discussion approval is claimed. Only the validator and its existing test file change.

Validation-only returns before app, server, Metro, simulator or emulator setup. No product UI or screenshot pixels change. The CLI evidence uses generated RGB files at 1320×2868 and 1080×1920, not app captures. No production app build is needed for this path.

Prior PRs: #4014, by @juliusmarminge, introduced the harness and validator. No earlier PR attempting this integrity fix was found. #14254, by @Bil0000, is separate Pen-export work and is not reused here; its maintainer deferral concerns that feature.

Verification

Linux, Node 24.22.0:

  • vp test run scripts/mobile-showcase.test.ts --no-cache: against main's mobile-showcase.ts, the three corruption tests fail and the other four pass. All seven pass with this change.
  • node scripts/mobile-showcase.ts --validate-only --device iphone-6.9 --appearance dark --theme t3-code, repeated with --device pixel: base accepts intact, truncated and restored files with exit 0. Candidate accepts intact and restored files, but names the truncated asset and exits 1. Each capture set contains six generated screenshots.
  • tsc-rs --noEmit -p scripts/tsconfig.json: passes.
  • vp lint scripts/mobile-showcase.ts scripts/mobile-showcase.test.ts: passes, including main's current test lint rules.
  • vp fmt --check scripts/mobile-showcase.ts scripts/mobile-showcase.test.ts: passes. git diff --check and the merge check against green main also pass.

The new corruption tests fail on base, then all seven tests pass on the candidate.

PNG integrity regression test output

Base accepts truncated files. Candidate rejects them for both capture sets and passes again after restoration.

Validation-only CLI before and after

Not checked: native screenshot capture, App Store or Google Play uploads, production app builds, and the full repository suite. This command path neither captures nor uploads screenshots.

Production fix, tests, PR description and images written with GPT-6.1 Sol in T3 Code Nightly.

🤖 Generated with GPT-6.1 Sol in T3 Code Nightly

only21mil and others added 2 commits October 20, 2026 21:11
Decode store assets before reporting validation success. Retain the source metadata checks and identify corrupt assets by label. Add focused truncation and checksum regressions.

Co-Authored-By: GPT-6.1 Sol <noreply@openai.com>
Exercise offset byte views, metadata-only files, truncation inside IDAT and damaged IDAT checksums. Recover the lane test improvements without unrelated file-size coverage.

Co-Authored-By: GPT-6.1 Sol <noreply@openai.com>
@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4970288d-c063-45f1-bcca-4f64e240c03d
📥 Commits

Reviewing files that changed from the base of the PR and between b5a226e and 7c7d32a.

📒 Files selected for processing: 2
  • scripts/mobile-showcase.test.ts
  • scripts/mobile-showcase.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Oct 21, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 7c7d32a

Macroscope's review found this PR approvable — This is a small, self-contained fix in host-side screenshot tooling: validation now decodes PNG data and rejects truncated or corrupt assets while preserving valid asset handling. The accompanying regression tests cover the new validation cases without affecting product runtime.

You can add or adjust custom eligibility rules. Learn more.

This branch has not been deployed

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

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant