Identify SVG files that start with a BOM character

This commit is contained in:
Jamie Wilson 2021-04-13 18:07:59 -04:00
parent 31ea417d8e
commit 5dd8301141
No known key found for this signature in database
GPG Key ID: 971AE266EB620193
3 changed files with 7 additions and 1 deletions

View File

@ -562,7 +562,7 @@ class FastImage
:webp if @stream.peek(12)[8..11] == "WEBP"
when "<s"
:svg if @stream.peek(4) == "<svg"
when /\s\s|\s<|<[?!]/
when /\s\s|\s<|<[?!]/, 0xef.chr + 0xbb.chr
# Peek 10 more chars each time, and if end of file is reached just raise
# unknown. We assume the <svg tag cannot be within 10 chars of the end of
# the file, and is within the first 250 chars.

5
test/fixtures/test6.svg vendored Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="450" height="450" viewBox="0 0 450 450" overflow="visible" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path d='M5,19h9l-1,68h-9z' fill='#e80028'/>
</svg>

View File

@ -48,6 +48,7 @@ GoodFixtures = {
"heic/heic-maybebroken.HEIC"=>[:heic,[4032,3024]],
"heic/heic-single.heic"=>[:heif,[1440,960]],
"heic/heic-collection.heic"=>[:heif,[1440,960]],
"test6.svg" => [:svg, [450, 450]]
}
BadFixtures = [