png: check magic bytes for well-formed files

Closes #$250
This commit is contained in:
Andy Meneely
2018-08-09 13:12:30 -04:00
parent 8f15c21dcf
commit 5a8b3c5fcd
6 changed files with 50 additions and 2 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

+1
View File
@@ -0,0 +1 @@
Not a PNG.
+20
View File
@@ -0,0 +1,20 @@
require 'spec_helper'
require 'squib/graphics/image'
describe Squib do
context :open_png do
it 'opens a real image file' do
file = image_file('a.png')
expect(Squib.open_png(file)).to respond_to(:format) # loaded?
end
it 'fails on a non-PNG file' do
file = image_file('not_a_png.txt')
expect { Squib.open_png(file) }.
to raise_error(ArgumentError, /is not a PNG file/)
end
end
end
+4
View File
@@ -42,6 +42,10 @@ def csv_file(file)
"#{File.expand_path(File.dirname(__FILE__))}/data/csv/#{file}"
end
def image_file(file)
"#{File.expand_path(File.dirname(__FILE__))}/data/images/#{file}"
end
def xlsx_file(file)
"#{File.expand_path(File.dirname(__FILE__))}/data/xlsx/#{file}"
end