Skip to content

Commit a33bd1a

Browse files
committed
This closes qax-os#2019, closes qax-os#2150, fix panic on get string item with invalid offset range
- Update unit test
1 parent c5934ea commit a33bd1a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

cell_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,9 @@ func TestSharedStringsError(t *testing.T) {
11781178
assert.True(t, ok)
11791179
f.tempFiles.Store(defaultXMLPathSharedStrings, "")
11801180
assert.Equal(t, "1", f.getFromStringItem(1))
1181+
// Test get from string item with invalid offset range
1182+
f.sharedStringItem = [][]uint{{0}}
1183+
assert.Equal(t, "0", f.getFromStringItem(0))
11811184
// Cleanup undelete temporary files
11821185
assert.NoError(t, os.Remove(tempFile.(string)))
11831186
// Test reload the file error on set cell value and rich text. The error message was different between macOS and Windows

rows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ func (f *File) getFromStringItem(index int) string {
355355
return strconv.Itoa(index)
356356
}
357357
offsetRange := f.sharedStringItem[index]
358+
if len(offsetRange) != 2 || offsetRange[0] >= offsetRange[1] {
359+
return strconv.Itoa(index)
360+
}
358361
buf := make([]byte, offsetRange[1]-offsetRange[0])
359362
if _, err := f.sharedStringTemp.ReadAt(buf, int64(offsetRange[0])); err != nil {
360363
return strconv.Itoa(index)

0 commit comments

Comments
 (0)