-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdefinedname_security_test.go
More file actions
46 lines (41 loc) · 937 Bytes
/
definedname_security_test.go
File metadata and controls
46 lines (41 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package werkbook
import (
"bytes"
"errors"
"strings"
"testing"
"github.com/jpoz/werkbook/formula"
"github.com/jpoz/werkbook/ooxml"
)
func TestOpenReaderAtRejectsOversizedDefinedNameExpansion(t *testing.T) {
data := &ooxml.WorkbookData{
Sheets: []ooxml.SheetData{
{
Name: "Sheet1",
Rows: []ooxml.RowData{
{
Num: 1,
Cells: []ooxml.CellData{
{Ref: "A1", Formula: "Huge+Huge"},
},
},
},
},
},
DefinedNames: []ooxml.DefinedName{
{
Name: "Huge",
Value: strings.Repeat("1", formula.MaxExpandedFormulaBytes/2+1),
LocalSheetID: -1,
},
},
}
var buf bytes.Buffer
if err := ooxml.WriteWorkbook(&buf, data); err != nil {
t.Fatalf("WriteWorkbook error: %v", err)
}
_, err := OpenReaderAt(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
if !errors.Is(err, ErrFormulaTooLarge) {
t.Fatalf("expected ErrFormulaTooLarge, got %v", err)
}
}