Skip to content

Commit 852332e

Browse files
feat(snapshots): Add 40M pixel limit validation for snapshot images
Validate image pixel counts before uploading to catch oversized images early, matching the backend's MAX_DIFF_PIXELS limit. Images exceeding 40,000,000 pixels are reported with their dimensions and the command fails before wasting bandwidth on uploads that would be rejected. Refs EME-885 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c84fd84 commit 852332e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/commands/build/snapshots.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const EXPERIMENTAL_WARNING: &str =
2121
The command is subject to breaking changes, including removal, in any Sentry CLI release.";
2222

2323
const IMAGE_EXTENSIONS: &[&str] = &["png", "jpg", "jpeg"];
24+
const MAX_PIXELS_PER_IMAGE: u64 = 40_000_000;
2425

2526
pub fn make_command(command: Command) -> Command {
2627
command
@@ -88,6 +89,8 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
8889
if images.len() == 1 { "file" } else { "files" }
8990
);
9091

92+
validate_image_sizes(&images)?;
93+
9194
// Upload image files to objectstore
9295
println!(
9396
"{} Uploading {} image {}",
@@ -166,6 +169,37 @@ fn collect_image_info(dir: &Path, path: &Path) -> Option<ImageInfo> {
166169
})
167170
}
168171

172+
fn validate_image_sizes(images: &[ImageInfo]) -> Result<()> {
173+
let violations: Vec<_> = images
174+
.iter()
175+
.filter_map(|img| {
176+
let pixels = img.width as u64 * img.height as u64;
177+
if pixels > MAX_PIXELS_PER_IMAGE {
178+
Some((img, pixels))
179+
} else {
180+
None
181+
}
182+
})
183+
.collect();
184+
185+
if !violations.is_empty() {
186+
eprintln!("error: The following images exceed the maximum pixel limit of 40,000,000:");
187+
for (img, pixels) in &violations {
188+
let path = img.relative_path.display();
189+
let width = img.width;
190+
let height = img.height;
191+
eprintln!(" {path} ({width}x{height} = {pixels} pixels)");
192+
}
193+
anyhow::bail!(
194+
"{} image{} exceeded the maximum pixel limit of 40,000,000",
195+
violations.len(),
196+
if violations.len() == 1 { "" } else { "s" }
197+
);
198+
}
199+
200+
Ok(())
201+
}
202+
169203
fn compute_sha256_hash(data: &[u8]) -> String {
170204
let mut hasher = Sha256::new();
171205
hasher.update(data);

0 commit comments

Comments
 (0)