Skip to content

Commit

Permalink
Merge pull request from GHSA-3qm5-5hmp-8c6w
Browse files Browse the repository at this point in the history
* Limit the size of the content type definition in OOXML

* Improve naming in OOXML tests

* Check OOXML error type in tests
  • Loading branch information
jupenur authored Jan 18, 2024
1 parent 232da35 commit 6e3f875
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docx.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func getContentTypeDefinition(zf *zip.File) (*contentTypeDefinition, error) {
defer f.Close()

x := &contentTypeDefinition{}
if err := xml.NewDecoder(f).Decode(x); err != nil {
if err := xml.NewDecoder(io.LimitReader(f, maxBytes)).Decode(x); err != nil {
return nil, err
}
return x, nil
Expand Down
16 changes: 16 additions & 0 deletions docx_test/docx_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package docx_test

import (
"encoding/xml"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -50,3 +51,18 @@ func TestConvertDocxWithUncommonValidStructure(t *testing.T) {
t.Errorf("expected %v to contains %v", resp, want)
}
}


func TestConvertDocxDecompressionSizeLimit(t *testing.T) {
f, err := os.Open("./testdata/decompression_size_limit.docx")
if err != nil {
t.Fatalf("got error = %v, want nil", err)
}
_, _, err = docconv.ConvertDocx(f)
if _, ok := err.(*xml.SyntaxError); !ok {
t.Errorf("got error = %T, want *xml.SyntaxError", err)
}
if want := "EOF"; !strings.Contains(err.Error(), want) {
t.Errorf("got error = %v, want %v", err, want)
}
}
Binary file added docx_test/testdata/decompression_size_limit.docx
Binary file not shown.
15 changes: 15 additions & 0 deletions pptx_test/pptx_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package docx_test

import (
"encoding/xml"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -30,3 +31,17 @@ func TestConvertPptx(t *testing.T) {
t.Errorf("expected %v to contain %v", resp, want)
}
}

func TestConvertPptxDecompressionSizeLimit(t *testing.T) {
f, err := os.Open("./testdata/decompression_size_limit.pptx")
if err != nil {
t.Fatalf("got error = %v, want nil", err)
}
_, _, err = docconv.ConvertPptx(f)
if _, ok := err.(*xml.SyntaxError); !ok {
t.Errorf("got error = %T, want *xml.SyntaxError", err)
}
if want := "EOF"; !strings.Contains(err.Error(), want) {
t.Errorf("got error = %v, want %v", err, want)
}
}
Binary file added pptx_test/testdata/decompression_size_limit.pptx
Binary file not shown.

0 comments on commit 6e3f875

Please sign in to comment.