Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlehane committed Sep 14, 2024
1 parent 2e9a4d7 commit 473ed41
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 58 deletions.
11 changes: 1 addition & 10 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,14 @@ import (
"github.com/richardlehane/msoleps/types"
)

//objectType types
// objectType types
const (
unknown uint8 = 0x0 // this means unallocated - typically zeroed dir entries
storage uint8 = 0x1 // this means dir
stream uint8 = 0x2 // this means file
rootStorage uint8 = 0x5 // this means root
)

// color flags
const (
red uint8 = 0x0
black uint8 = 0x1
)

const lenDirEntry int = 64 + 4*4 + 16 + 4 + 8*2 + 4 + 8

type directoryEntryFields struct {
rawName [32]uint16 //64 bytes, unicode string encoded in UTF-16. If root, "Root Entry\0" w
nameLength uint16 //2 bytes
Expand Down Expand Up @@ -177,7 +169,6 @@ func (r *Reader) traverse() error {
if file.rightSibID != noStream {
recurse(int(file.rightSibID), path)
}
return
}
recurse(0, []string{})
return err
Expand Down
12 changes: 5 additions & 7 deletions file_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package mscfb

import (
"testing"
)
import "testing"

func equal(a [][2]int64, b [][2]int64) bool {
if len(a) != len(b) {
Expand All @@ -17,14 +15,14 @@ func equal(a [][2]int64, b [][2]int64) bool {
}

func TestCompress(t *testing.T) {
a := [][2]int64{[2]int64{4608, 1024}, [2]int64{5632, 1024}, [2]int64{6656, 1024}, [2]int64{7680, 1024}, [2]int64{8704, 1024}, [2]int64{9728, 1024}, [2]int64{10752, 512}}
ar := [][2]int64{[2]int64{4608, 6656}}
a := [][2]int64{{4608, 1024}, {5632, 1024}, {6656, 1024}, {7680, 1024}, {8704, 1024}, {9728, 1024}, {10752, 512}}
ar := [][2]int64{{4608, 6656}}
a = compressChain(a)
if !equal(a, ar) {
t.Errorf("Streams compress fail; Expecting: %v, Got: %v", ar, a)
}
b := [][2]int64{[2]int64{4608, 1024}, [2]int64{6656, 1024}, [2]int64{7680, 1024}, [2]int64{8704, 1024}, [2]int64{10752, 512}}
br := [][2]int64{[2]int64{4608, 1024}, [2]int64{6656, 3072}, [2]int64{10752, 512}}
b := [][2]int64{{4608, 1024}, {6656, 1024}, {7680, 1024}, {8704, 1024}, {10752, 512}}
br := [][2]int64{{4608, 1024}, {6656, 3072}, {10752, 512}}
b = compressChain(b)
if !equal(b, br) {
t.Errorf("Streams compress fail; Expecting: %v, Got: %v", br, b)
Expand Down
2 changes: 2 additions & 0 deletions fuzz.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build gofuzz
// +build gofuzz

// fuzzing with https://github.com/dvyukov/go-fuzz
Expand All @@ -8,6 +9,7 @@ import (
"io"
)

// todo: replace with Fuzzing from go test package
func Fuzz(data []byte) int {
doc, err := New(bytes.NewReader(data))
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions mscfb.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ func (r *Reader) Read(b []byte) (n int, err error) {
// Debug provides granular information from an mscfb file to assist with debugging
func (r *Reader) Debug() map[string][]uint32 {
ret := map[string][]uint32{
"sector size": []uint32{r.sectorSize},
"sector size": {r.sectorSize},
"mini fat locs": r.header.miniFatLocs,
"mini stream locs": r.header.miniStreamLocs,
"directory sector": []uint32{r.header.directorySectorLoc},
"mini stream start/size": []uint32{r.File[0].startingSectorLoc, binary.LittleEndian.Uint32(r.File[0].streamSize[:])},
"directory sector": {r.header.directorySectorLoc},
"mini stream start/size": {r.File[0].startingSectorLoc, binary.LittleEndian.Uint32(r.File[0].streamSize[:])},
}
for f, err := r.Next(); err == nil; f, err = r.Next() {
ret[f.Name+" start/size"] = []uint32{f.startingSectorLoc, binary.LittleEndian.Uint32(f.streamSize[:])}
Expand Down
54 changes: 16 additions & 38 deletions mscfb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mscfb
import (
"bytes"
"io"
"io/ioutil"
"log"
"os"
"sync"
Expand All @@ -17,66 +16,45 @@ var (
testPpt = "test/test.ppt"
testMsg = "test/test.msg"
testEntries = []*File{
&File{Name: "Root Node",
{Name: "Root Node",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: noStream, childID: 1},
},
&File{Name: "Alpha",
{Name: "Alpha",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: 2, childID: noStream},
},
&File{Name: "Bravo",
{Name: "Bravo",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: 3, childID: 5},
},
&File{Name: "Charlie",
{Name: "Charlie",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: noStream, childID: 7},
},
&File{Name: "Delta",
{Name: "Delta",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: noStream, childID: noStream},
},
&File{Name: "Echo",
{Name: "Echo",
directoryEntryFields: &directoryEntryFields{leftSibID: 4, rightSibID: 6, childID: 9},
},
&File{Name: "Foxtrot",
{Name: "Foxtrot",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: noStream, childID: noStream},
},
&File{Name: "Golf",
{Name: "Golf",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: noStream, childID: 10},
},
&File{Name: "Hotel",
{Name: "Hotel",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: noStream, childID: noStream},
},
&File{Name: "Indigo",
{Name: "Indigo",
directoryEntryFields: &directoryEntryFields{leftSibID: 8, rightSibID: noStream, childID: 11},
},
&File{Name: "Jello",
{Name: "Jello",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: noStream, childID: noStream},
},
&File{Name: "Kilo",
{Name: "Kilo",
directoryEntryFields: &directoryEntryFields{leftSibID: noStream, rightSibID: noStream, childID: noStream},
},
}
)

func equals(a, b []int) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}

func empty(sl []byte) bool {
for _, v := range sl {
if v != 0 {
return false
}
}
return true
}

func testFile(t *testing.T, path string) {
file, _ := os.Open(path)
defer file.Close()
Expand Down Expand Up @@ -155,13 +133,13 @@ func TestConcurrentAccess(t *testing.T) {
var wg sync.WaitGroup
wg.Add(len(doc.File))
for _, f := range doc.File {
go func() {
go func(ff *File) {
defer wg.Done()
_, err := io.Copy(io.Discard, f)
_, err := io.Copy(io.Discard, ff)
if err != nil {
log.Println(err)
}
}()
}(f)
}
wg.Wait()
}
Expand Down Expand Up @@ -306,7 +284,7 @@ func TestWrite(t *testing.T) {

func benchFile(b *testing.B, path string) {
b.StopTimer()
buf, _ := ioutil.ReadFile(path)
buf, _ := os.ReadFile(path)
entrybuf := make([]byte, 32000)
b.StartTimer()
rdr := bytes.NewReader(buf)
Expand Down

0 comments on commit 473ed41

Please sign in to comment.