format_parser 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf7fbbf842a1ae6fcde3986b360877223ac699a87950848b508da15f8a8280ad
4
- data.tar.gz: 29882db7afe75a1d3b6554f18dbc837cefb1dbe9e8927adafe959ac8d37ade84
3
+ metadata.gz: 6402f116eddca928e4807f76d4631f052a841c360137833310900b9604107997
4
+ data.tar.gz: 62e2a34f739d912f850e1e732c3e9cc154eadcaff5c76cc0f56fc163298e9192
5
5
  SHA512:
6
- metadata.gz: 0cf33f73ac298f565020e9819c9c7d2e2af340490b869b97a008b4466ac2b0825fed70d5d9e255ef1192520cef92fdeeff0c7ade18d5e38910d6dc2fd0de89f3
7
- data.tar.gz: c20cdc92df0d29d1e0c4b9f8c05644e17216f239a8d90e9c7af38f5566b4abaaf6f6289d5cc69d6a25b0ed644236403820b5c3402080f0b7ba40ca112b671d3a
6
+ metadata.gz: 9385682da9e3a86f67e25cf3491c90f8993a4073a9378f33d20e470f5917dea9afe913c29c16f17412e5f46fb226b8016c51a18327eee74b5f624e304d227c83
7
+ data.tar.gz: 2aa680436faa13496921e6134b3b3c341bd0e0b21c1a2a8656e3102165bb6f5bdec941790797861720f840283a171dc9501ae572f4048c8fbe76393badb8bdea
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.4.1
2
+ * Skip Exif chunks that are malformed during `WEBP` parsing.
3
+
1
4
  ## 1.4.0
2
5
  * Add support for `WEBP` lossy, lossless and extended file formats.
3
6
 
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '1.4.0'
2
+ VERSION = '1.4.1'
3
3
  end
@@ -129,7 +129,7 @@ class FormatParser::WebpParser
129
129
  # Try to read the next chunk header, and break the loop if we've reached EOF.
130
130
  begin
131
131
  fourcc, chunk_size = safe_read(@buf, 8).unpack('A4V')
132
- rescue InvalidRead
132
+ rescue FormatParser::IOUtils::InvalidRead
133
133
  break
134
134
  end
135
135
 
@@ -138,11 +138,18 @@ class FormatParser::WebpParser
138
138
 
139
139
  case fourcc
140
140
  when 'EXIF'
141
- exif = exif_from_tiff_io(StringIO.new(safe_read(@buf, chunk_size)))
142
- # We use ||= here as one Exif chunk at most should be present, even though it is possible for there to be more.
143
- intrinsics[:exif] ||= exif
144
- image.height_px, image.width_px = image.width_px, image.height_px if exif&.rotated?
145
- image.orientation = exif&.orientation_sym
141
+ chunk_pos = @buf.pos
142
+ begin
143
+ exif = exif_from_tiff_io(StringIO.new(safe_read(@buf, chunk_size)))
144
+ # We use ||= here as one Exif chunk at most should be present, even though it is possible for there to be more.
145
+ intrinsics[:exif] ||= exif
146
+ image.height_px, image.width_px = image.width_px, image.height_px if exif&.rotated?
147
+ image.orientation = exif&.orientation_sym
148
+ rescue EXIFR::MalformedTIFF
149
+ # Exif data was malformed and could not be parsed. Need to ensure that buffer is pointing at the next chunk.
150
+ @buf.seek(chunk_pos + chunk_size)
151
+ next
152
+ end
146
153
  when 'XMP'
147
154
  # We use ||= here as one XMP chunk at most should be present, even though it is possible for there to be more.
148
155
  intrinsics[:xmp] ||= safe_read(@buf, chunk_size)
@@ -118,4 +118,19 @@ describe FormatParser::WebpParser do
118
118
  expect(result.orientation).to be_nil
119
119
  expect(result.width_px).to eq(211)
120
120
  end
121
+
122
+ it 'successfully skips malformed Exif chunks' do
123
+ result = subject.call(File.open(fixtures_dir + 'WEBP/extended-malformed-exif.webp', 'rb'))
124
+ expect(result).not_to be_nil
125
+ expect(result.content_type).to eq('image/webp')
126
+ expect(result.format).to eq(:webp)
127
+ expect(result.has_multiple_frames).to eq(false)
128
+ expect(result.has_transparency).to eq(false)
129
+ expect(result.height_px).to eq(181)
130
+ expect(result.intrinsics).not_to be_nil
131
+ expect(result.intrinsics[:exif]).to be_nil
132
+ expect(result.intrinsics[:xmp]).not_to be_nil
133
+ expect(result.orientation).to be_nil
134
+ expect(result.width_px).to eq(65)
135
+ end
121
136
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-07-07 00:00:00.000000000 Z
12
+ date: 2022-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ks