exifr 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ EXIF Reader 1.0.3
2
+ * enhancement; "raise specific exception to allow better error handling"; thanks to James Miller
3
+
1
4
  EXIF Reader 1.0.2
2
5
  * bug fix; "[GH#9/12] no block given"; thanks to Ian Leitch
3
6
 
@@ -0,0 +1,5 @@
1
+ module EXIFR
2
+ class MalformedImage < StandardError; end
3
+ class MalformedJPEG < MalformedImage; end
4
+ class MalformedTIFF < MalformedImage; end
5
+ end
@@ -2,3 +2,4 @@
2
2
 
3
3
  require 'jpeg'
4
4
  require 'tiff'
5
+ require 'exceptions'
@@ -86,14 +86,18 @@ module EXIFR
86
86
  end
87
87
  end unless io.respond_to? :readsof
88
88
 
89
- raise 'malformed JPEG' unless io.readbyte == 0xFF && io.readbyte == 0xD8 # SOI
89
+ unless io.readbyte == 0xFF && io.readbyte == 0xD8 # SOI
90
+ raise MalformedJPEG, "no start of image marker found"
91
+ end
90
92
 
91
93
  app1s = []
92
94
  while marker = io.next
93
95
  case marker
94
96
  when 0xC0..0xC3, 0xC5..0xC7, 0xC9..0xCB, 0xCD..0xCF # SOF markers
95
97
  length, @bits, @height, @width, components = io.readsof
96
- raise 'malformed JPEG' unless length == 8 + components * 3
98
+ unless length == 8 + components * 3
99
+ raise MalformedJPEG, "frame length does not match number of components"
100
+ end
97
101
  when 0xD9, 0xDA; break # EOI, SOS
98
102
  when 0xFE; (@comment ||= []) << io.readframe # COM
99
103
  when 0xE1; app1s << io.readframe # APP1, may contain EXIF tag
@@ -511,7 +511,7 @@ module EXIFR
511
511
  def sign_byte(n)
512
512
  (n & 0x80) != 0 ? n - 0x100 : n
513
513
  end
514
-
514
+
515
515
  def sign_short(n)
516
516
  (n & 0x8000) != 0 ? n - 0x10000 : n
517
517
  end
@@ -540,7 +540,8 @@ module EXIFR
540
540
  case self[0..1]
541
541
  when 'II'; @short, @long = 'v', 'V'
542
542
  when 'MM'; @short, @long = 'n', 'N'
543
- else; raise 'no II or MM marker found'
543
+ else
544
+ raise MalformedTIFF, "no byte order information found"
544
545
  end
545
546
  end
546
547
 
@@ -18,6 +18,12 @@ class JPEGTest < Test::Unit::TestCase
18
18
  end
19
19
  end
20
20
  end
21
+
22
+ def test_raises_malformed_jpeg
23
+ assert_raise MalformedJPEG do
24
+ JPEG.new(StringIO.new("djibberish"))
25
+ end
26
+ end
21
27
 
22
28
  def test_size
23
29
  j = JPEG.new(f('image.jpg'))
@@ -22,6 +22,12 @@ class TIFFTest < Test::Unit::TestCase
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ def test_raises_malformed_tiff
27
+ assert_raise MalformedTIFF do
28
+ TIFF.new(StringIO.new("djibberish"))
29
+ end
30
+ end
25
31
 
26
32
  def test_multiple_images
27
33
  assert_equal 2, @t.size
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exifr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.W. van 't Veer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-04 00:00:00 +02:00
18
+ date: 2010-09-10 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -34,6 +34,7 @@ files:
34
34
  - lib/exifr.rb
35
35
  - lib/jpeg.rb
36
36
  - lib/tiff.rb
37
+ - lib/exceptions.rb
37
38
  - tests/data/1x1.jpg
38
39
  - tests/data/apple-aperture-1.5.exif
39
40
  - tests/data/canon-g3.exif