Skip to content

Commit

Permalink
prevent variant types from recursing
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlehane committed Apr 30, 2022
1 parent 9fbcd88 commit 5eed41e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 3 additions & 3 deletions msoleps.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// if oerr := props.Reset(doc); oerr != nil {
// log.Fatal(oerr)
// }
// for prop := range props.Property {
// for _, prop := range props.Property {
// fmt.Printf("Name: %s; Type: %s; Value: %v", prop.Name, prop.Type(), prop)
// }
// }
Expand Down Expand Up @@ -134,7 +134,7 @@ func (r *Reader) start(rdr io.Reader) error {
r.Property[i].T = types.Null{}
continue
}
t, _ := types.Evaluate(r.buf[int(v.offset+pss.offsetA):])
t, _ := types.Evaluate(r.buf[int(v.offset+pss.offsetA):]) // ignore errors for now as not all types implemented
if t.Type() == "CodeString" {
cs := t.(*types.CodeString)
cs.SetId(ps.code)
Expand Down Expand Up @@ -162,7 +162,7 @@ func (r *Reader) start(rdr io.Reader) error {
r.Property[i].T = types.Null{}
continue
}
t, _ := types.Evaluate(r.buf[int(v.offset+pss.offsetB):])
t, _ := types.Evaluate(r.buf[int(v.offset+pss.offsetB):]) // ignore errors for now as not all types implemented
if t.Type() == "CodeString" {
cs := t.(*types.CodeString)
cs.SetId(psb.code)
Expand Down
1 change: 1 addition & 0 deletions msoleps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
testDocSum = "test/DocumentSummaryInformation"
testSum = "test/SummaryInformation"
testSum1 = "test/SummaryInformation1"
testBad = "test/SummaryInformationBad"
)

func testFile(t *testing.T, path string) *Reader {
Expand Down
10 changes: 8 additions & 2 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type Type interface {
}

const (
vector uint16 = iota + 1
scalar uint16 = iota
vector
array
)

Expand All @@ -52,8 +53,13 @@ func Evaluate(b []byte) (Type, error) {
return MakeVector(f, b[4:])
case array:
return MakeArray(f, b[4:])
case scalar:
if id != VT_VARIANT { // a VT_VARIANT can only be in a vector or array
return f(b[4:])
}
}
return f(b[4:])
return I1(0), ErrUnknownType

}

type TypeID uint16
Expand Down
14 changes: 13 additions & 1 deletion types/vectorArray.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (a Array) Length() int {
return 0
}

// not implemented yet
func MakeArray(f MakeType, b []byte) (Type, error) {
return Array{}, nil
}
Expand All @@ -95,7 +96,18 @@ func (v Variant) Length() int {
}

func MakeVariant(b []byte) (Type, error) {
t, err := Evaluate(b)
if len(b) < 4 || binary.LittleEndian.Uint16(b[2:4]) != scalar { // only scalar values allowed
return Variant{}, ErrType
}
id := TypeID(binary.LittleEndian.Uint16(b[:2]))
if id == VT_VARIANT {
return Variant{}, ErrType // no recursive types allowed
}
f, ok := MakeTypes[id]
if !ok {
return I1(0), ErrUnknownType
}
t, err := f(b[4:])
if err != nil {
return Variant{}, err
}
Expand Down

0 comments on commit 5eed41e

Please sign in to comment.