Skip to content

feat: enforce 500KB size limit on raw image buffer ingestion - #28

Merged
REX-codebase merged 1 commit into
mainfrom
jules/image-size-guardrail-js0-a91889c7-2a1e-46f5-ba26-5dc021b14bef
Jul 18, 2026
Merged

REX-codebase merged 1 commit into
mainfrom
jules/image-size-guardrail-js0-a91889c7-2a1e-46f5-ba26-5dc021b14bef

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

Problem & Context

Currently, our system processes image buffers without validating their file size at ingestion. This allows unoptimized assets (greater than 500KB) to bypass performance gates and proceed to decoding, which degrades system performance and compromises our Largest Contentful Paint (LCP) targets.

To protect system stability and performance, we need a strict, low-overhead guardrail that halts the processing of oversized assets immediately.

Key Decisions & Rationale

  • Early Validation (Pre-Decompression): Decompressing and parsing PNG/image files is highly CPU- and memory-intensive. By validating the raw buffer length (buffer.length) as the very first step, we fail-fast and prevent costly decompression cycles for oversized files.
  • Strict 500KB (512,000 Bytes) Limit: We enforce a hard limit of exactly 500KB (calculated as 500 * 1024 bytes) for binary precision. Softer targets, such as the 100KB sustainability budget, are deliberately omitted from this blocker and reserved for downstream soft-auditing tiers.
  • Zero External Dependencies: To keep the codebase lightweight and highly secure, we rely entirely on native buffer size properties rather than introducing external image metadata or manipulation libraries.
  • No Auto-Remediation: Automated resizing or compression is intentionally omitted to keep this performance guardrail simple, robust, and predictable. If a file is too large, the system rejects it and throws a fatal error so the upstream caller can handle the failure cleanly.

Changes Made

  • Integrated a raw buffer check at the entry point of image ingestion (prior to decoding or parsing).
  • Configured the system to throw a descriptive, fatal error specifying that the asset was rejected due to exceeding the 500KB performance budget.
  • Ensured assets within the budget limit (under 500KB) proceed directly to parsing without any overhead or latency.

Verification Results

  • Rejection Test: Verified that a 501KB file triggers a fatal error and halts analysis immediately.
  • Acceptance Test: Verified that a 499KB file bypasses the guardrail and parses successfully.
  • Dependency Audit: Confirmed no new packages or configurations were added.

@REX-codebase
REX-codebase merged commit a4cade8 into main Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant