1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
From aa16ef97ab23c52b34c43e9d98d7f3cb56ad35f1 Mon Sep 17 00:00:00 2001
From: Lukasz Anforowicz <lukasza@chromium.org>
Date: Fri, 17 Jan 2025 23:10:45 +0000
Subject: [PATCH] Add support for parsing `eXIf` chunk.
The `eXIf` chunk was already supported in `encoder.rs`, but this commit
also adds support to `decoder/stream.rs`. This commit is needed for
parity with the existing PNG decoder in Blink / Chromium - see
https://crbug.com/390707316
---
src/decoder/stream.rs | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/third_party/rust/chromium_crates_io/vendor/png-0.17.14/src/decoder/stream.rs b/third_party/rust/chromium_crates_io/vendor/png-0.17.14/src/decoder/stream.rs
index 1b00968..904d3be 100644
--- a/third_party/rust/chromium_crates_io/vendor/png-0.17.14/src/decoder/stream.rs
+++ b/third_party/rust/chromium_crates_io/vendor/png-0.17.14/src/decoder/stream.rs
@@ -989,6 +989,7 @@ impl StreamingDecoder {
chunk::cICP => Ok(self.parse_cicp()),
chunk::mDCV => Ok(self.parse_mdcv()),
chunk::cLLI => Ok(self.parse_clli()),
+ chunk::eXIf => Ok(self.parse_exif()),
chunk::bKGD => Ok(self.parse_bkgd()),
chunk::iCCP if !self.decode_options.ignore_iccp_chunk => self.parse_iccp(),
chunk::tEXt if !self.decode_options.ignore_text_chunk => self.parse_text(),
@@ -1487,6 +1488,16 @@ impl StreamingDecoder {
Decoded::Nothing
}
+ fn parse_exif(&mut self) -> Decoded {
+ // We ignore a second, duplicated eXIf chunk (if any).
+ let info = self.info.as_mut().unwrap();
+ if info.exif_metadata.is_none() {
+ info.exif_metadata = Some(self.current_chunk.raw_bytes.clone().into());
+ }
+
+ Decoded::Nothing
+ }
+
fn parse_iccp(&mut self) -> Result<Decoded, DecodingError> {
if self.have_idat {
Err(DecodingError::Format(
@@ -2125,7 +2136,7 @@ mod tests {
assert!(decoder.read_info().is_ok());
}
- /// Test handling of `mDCV` and `cLLI` chunks.`
+ /// Test handling of `mDCV` and `cLLI` chunks.
#[test]
fn test_mdcv_and_clli_chunks() {
let decoder = crate::Decoder::new(File::open("tests/bugfixes/cicp_pq.png").unwrap());
@@ -2155,6 +2166,17 @@ mod tests {
assert_relative_eq!(clli.max_frame_average_light_level as f32 / 10_000.0, 2627.0);
}
+ /// Test handling of `eXIf` chunk.
+ #[test]
+ fn test_exif_chunk() {
+ let decoder =
+ crate::Decoder::new(File::open("tests/bugfixes/F-exif-chunk-early.png").unwrap());
+ let reader = decoder.read_info().unwrap();
+ let info = reader.info();
+ let exif = info.exif_metadata.as_ref().unwrap().as_ref();
+ assert_eq!(exif.len(), 90);
+ }
+
/// Tests what happens then [`Reader.finish`] is called twice.
#[test]
fn test_finishing_twice() {
--
2.48.1.262.g85cc9f2d1e-goog
|