format_parser 0.13.2 → 0.13.3

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: 9387f32c6af3a32839c958afe0fb79352e7a19e99edef5d6fc33dc2102c0d403
4
- data.tar.gz: c78134703d9c6cf6e243dadeab0962e3c84a6f20d1ad42f5d52dbd66f2e8b610
3
+ metadata.gz: 6ef925f9f8fdd532ac2020248ca86200a5519243b1d061f9eeded80ef760b15c
4
+ data.tar.gz: 71a06ee9fb528d1ff89b2291e85383afa9bb480a048395bc08533271d0355a35
5
5
  SHA512:
6
- metadata.gz: 5e710c21e98deb50e6e88a8ba6f46254cb2224a9cfff618637b9380071e1f3a77029e3a024e46a6d4d45f1c6987a2638cb78b7f3aacc3dbcd55fc3308fe5a8f9
7
- data.tar.gz: '0858b0406ae6461ee63e961e3017eab71616779f29774e887eed7646e7f67db40711a1a3dd72d22665dd17dbd4131e9b7e8cbce0a5943a64d708a5b4bc25e468'
6
+ metadata.gz: f1cd0d8851cafd96762449310334b8c2a35e154aba4fbfbab7acae8f58a837f02fc55dea0f877a29a237651a373467226a78ceee2b8fb9f16bbbea97c2870141
7
+ data.tar.gz: 3b5ceb254bc8256abe0f53f6ff0f15e357f3c4e381bc82b411cb3fcfd57df368bcf18c3ad914506d7d43a5827a4654d54ceff569a8d39366184d2557bafdfcdf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.13.3
2
+ * Add a fixture to make sure all parsers can cope with an empty file when using `parse_http`
3
+ * Terminate the ZIP parser early with empty input
4
+ * Terminate the MP3 parser early with empty or too small input
5
+
1
6
  ## 0.13.2
2
7
  * Handle BMP files with pixel array offsets larger than 54
3
8
 
data/README.md CHANGED
@@ -115,6 +115,7 @@ Unless specified otherwise in this section the fixture files are MIT licensed an
115
115
  - `divergent_pixel_dimensions_exif.jpg` is used with permission from LiveKom GmbH
116
116
  - `extended_reads.jpg` has kindly been made available by Raphaelle Pellerin for use exclusively with format_parser
117
117
  - `too_many_APP1_markers_surrogate.jpg` was created by the project maintainers
118
+ * `orient_6.jpg` is used with permission from [Renaud Chaput](https://github.com/renchap)
118
119
 
119
120
  ### AIFF
120
121
  - fixture.aiff was created by one of the project maintainers and is MIT licensed
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '0.13.2'
2
+ VERSION = '0.13.3'
3
3
  end
@@ -2,6 +2,8 @@ require 'ks'
2
2
  require 'id3tag'
3
3
 
4
4
  class FormatParser::MP3Parser
5
+ include FormatParser::IOUtils
6
+
5
7
  require_relative 'mp3_parser/id3_extraction'
6
8
 
7
9
  class MPEGFrame < Ks.strict(:offset_in_file, :mpeg_id, :channels, :sample_rate, :frame_length, :frame_bitrate)
@@ -59,11 +61,13 @@ class FormatParser::MP3Parser
59
61
 
60
62
  # Special case: some ZIPs (Office documents) did detect as MP3s.
61
63
  # To avoid having that happen, we check for the PKZIP signature -
62
- # local entry header signature - at the very start of the file
63
- return if io.read(6) == ZIP_LOCAL_ENTRY_SIGNATURE
64
- io.seek(0)
64
+ # local entry header signature - at the very start of the file.
65
+ # If the file is too small safe_read will fail too and the parser
66
+ # will terminate here.
67
+ return if safe_read(io, 6) == ZIP_LOCAL_ENTRY_SIGNATURE
65
68
 
66
69
  # Read all the ID3 tags (or at least attempt to)
70
+ io.seek(0)
67
71
  id3v1 = ID3Extraction.attempt_id3_v1_extraction(io)
68
72
  tags = [id3v1, ID3Extraction.attempt_id3_v2_extraction(io)].compact
69
73
 
@@ -3,9 +3,11 @@ class FormatParser::ZIPParser
3
3
  require_relative 'zip_parser/office_formats'
4
4
 
5
5
  include OfficeFormats
6
+ include FormatParser::IOUtils
6
7
 
7
8
  def call(io)
8
9
  io = FormatParser::IOConstraint.new(io)
10
+ safe_read(io, 1) # Ensure the file is not empty
9
11
 
10
12
  reader = FileReader.new
11
13
  entries = reader.read_zip_structure(io: io)
@@ -104,4 +104,20 @@ describe FormatParser::JPEGParser do
104
104
  result = subject.call(File.open(kitten_path, 'rb'))
105
105
  expect(result).not_to be_nil
106
106
  end
107
+
108
+ it 'assigns correct orientation to the picture that has mutliple APP1 markers with EXIF tags' do
109
+ # https://github.com/sdsykes/fastimage/issues/102
110
+ # This case is peculiar in that (from what I could find)
111
+ # it is not really _defined_ which EXIF comment in the file should be considered
112
+ # the only one to be used, or whether they have to be "union'd" together, or tags
113
+ # coming later in the file should overwrite tags that occur earlier. From what I
114
+ # can observe the dimensions we are recovering here are correct and the rotation
115
+ # is correctly detected, but I am not entirely sure how FastImage needs to play
116
+ # it in this case.
117
+ pic_path = fixtures_dir + '/JPEG/orient_6.jpg'
118
+ result = subject.call(File.open(pic_path, 'rb'))
119
+ expect(result).not_to be_nil
120
+ expect(result.width_px).to eq(2500)
121
+ expect(result.display_width_px).to eq(1250) # The image is actually rotated
122
+ end
107
123
  end
@@ -80,4 +80,10 @@ describe FormatParser::MP3Parser do
80
80
 
81
81
  expect(parsed).to be_nil
82
82
  end
83
+
84
+ it 'terminates early with an IOUtils error when the file is too small' do
85
+ expect {
86
+ subject.call(StringIO.new(''))
87
+ }.to raise_error(FormatParser::IOUtils::InvalidRead)
88
+ end
83
89
  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: 0.13.2
4
+ version: 0.13.3
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: 2018-05-14 00:00:00.000000000 Z
12
+ date: 2018-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ks