Skip to content

Commit 2132e77

Browse files
committed
fix image parsing possibly panicking
1 parent 9320ee4 commit 2132e77

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/types/mod_json.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,10 @@ fn validate_mod_logo(file: &mut ZipFile) -> Result<Vec<u8>, ApiError> {
340340

341341
let (width, height) = img.dimensions();
342342

343-
encoder
344-
.write_image(img.as_bytes(), width, height, image::ColorType::Rgba8)
345-
.or(Err(ApiError::FilesystemError))?;
343+
if let Err(e) = encoder.write_image(img.as_bytes(), width, height, img.color()) {
344+
log::error!("{}", e);
345+
return Err(ApiError::BadRequest("Invalid logo.png".to_string()));
346+
}
346347
cursor.seek(std::io::SeekFrom::Start(0)).unwrap();
347348

348349
let mut bytes: Vec<u8> = vec![];

0 commit comments

Comments
 (0)