Skip to content

Commit

Permalink
Rename msoXML to zipContains
Browse files Browse the repository at this point in the history
It's a better name considering this function can be used to check any
kind of zip for headers, not only MS office files.
  • Loading branch information
gabriel-vasile committed Nov 17, 2021
1 parent fd5354c commit e4d5da0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions internal/magic/ms_office.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ var (

// Xlsx matches a Microsoft Excel 2007 file.
func Xlsx(raw []byte, limit uint32) bool {
return msoXML(raw, xlsxSigFiles...)
return zipContains(raw, xlsxSigFiles...)
}

// Docx matches a Microsoft Word 2007 file.
func Docx(raw []byte, limit uint32) bool {
return msoXML(raw, docxSigFiles...)
return zipContains(raw, docxSigFiles...)
}

// Pptx matches a Microsoft PowerPoint 2007 file.
func Pptx(raw []byte, limit uint32) bool {
return msoXML(raw, pptxSigFiles...)
return zipContains(raw, pptxSigFiles...)
}

// Ole matches an Open Linking and Embedding file.
Expand Down
9 changes: 4 additions & 5 deletions internal/magic/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,12 @@ func (t *zipTokenizer) next() (fileName string) {
return string(in[fNameOffset : fNameOffset+fNameLen])
}

// msoXML reads at most first 10 local headers and returns whether the input
// looks like a Microsoft Office file.
func msoXML(in []byte, prefixes ...string) bool {
// zipContains returns true if the zip file headers from in contain any of the paths.
func zipContains(in []byte, paths ...string) bool {
t := zipTokenizer{in: in}
for i, tok := 0, t.next(); tok != ""; i, tok = i+1, t.next() {
for p := range prefixes {
if strings.HasPrefix(tok, prefixes[p]) {
for p := range paths {
if strings.HasPrefix(tok, paths[p]) {
return true
}
}
Expand Down

0 comments on commit e4d5da0

Please sign in to comment.