Skip to content

Commit

Permalink
Merge pull request h2non#84 from evanoberholster/master
Browse files Browse the repository at this point in the history
Better matching and differentiation between CR2 and Tiff
  • Loading branch information
h2non authored May 20, 2020
2 parents dbd2467 + e44d0cf commit df519de
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions matchers/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ func Webp(buf []byte) bool {
}

func CR2(buf []byte) bool {
return len(buf) > 9 &&
((buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0) ||
(buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A)) &&
buf[8] == 0x43 && buf[9] == 0x52
return len(buf) > 10 &&
((buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0) || // Little Endian
(buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A)) && // Big Endian
buf[8] == 0x43 && buf[9] == 0x52 && // CR2 magic word
buf[10] == 0x02 // CR2 major version
}

func Tiff(buf []byte) bool {
return len(buf) > 9 &&
((buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0) ||
(buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A)) &&
// Differentiate Tiff from CR2
buf[8] != 0x43 && buf[9] != 0x52
return len(buf) > 10 &&
((buf[0] == 0x49 && buf[1] == 0x49 && buf[2] == 0x2A && buf[3] == 0x0) || // Little Endian
(buf[0] == 0x4D && buf[1] == 0x4D && buf[2] == 0x0 && buf[3] == 0x2A)) && // Big Endian
!CR2(buf) // To avoid conflicts differentiate Tiff from CR2
}

func Bmp(buf []byte) bool {
Expand Down

0 comments on commit df519de

Please sign in to comment.