20
0

FIX: fixed data reading errors

This commit is contained in:
sergeilem 2018-08-14 00:05:20 +03:00
parent cf12fc26e3
commit 1d8d5ec738

View File

@ -86,6 +86,11 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
case 0x042: // CODEPAGE case 0x042: // CODEPAGE
binary.Read(buf_item, binary.LittleEndian, &wb.Codepage) binary.Read(buf_item, binary.LittleEndian, &wb.Codepage)
case 0x3c: // CONTINUE case 0x3c: // CONTINUE
//FIX: sergeilem@gmail.com: step back if previous element not yet completed
if wb.continue_utf16 > 0 {
offset_pre--
}
if pre.Id == 0xfc { if pre.Id == 0xfc {
var size uint16 var size uint16
var err error var err error
@ -119,6 +124,8 @@ func (wb *WorkBook) parseBof(buf io.ReadSeeker, b *bof, pre *bof, offset_pre int
wb.sst = make([]string, info.Count) wb.sst = make([]string, info.Count)
var size uint16 var size uint16
var i = 0 var i = 0
//FIX: sergeilem@gmail.com: initialize offset
offset = i
for ; i < int(info.Count); i++ { for ; i < int(info.Count); i++ {
var err error var err error
if err = binary.Read(buf_item, binary.LittleEndian, &size); err == nil { if err = binary.Read(buf_item, binary.LittleEndian, &size); err == nil {
@ -192,10 +199,20 @@ func (w *WorkBook) get_string(buf io.ReadSeeker, size uint16) (res string, err e
if flag&0x1 != 0 { if flag&0x1 != 0 {
var bts = make([]uint16, size) var bts = make([]uint16, size)
var i = uint16(0) var i = uint16(0)
//FIX: sergeilem@gmail.com: we need local err here
var err error
for ; i < size && err == nil; i++ { for ; i < size && err == nil; i++ {
err = binary.Read(buf, binary.LittleEndian, &bts[i]) err = binary.Read(buf, binary.LittleEndian, &bts[i])
} }
runes := utf16.Decode(bts[:i])
//FIX: sergeilem@gmail.com: dont append extra
var runes []rune
if err == io.EOF {
runes = utf16.Decode(bts[:i-1])
} else {
runes = utf16.Decode(bts[:i])
}
res = string(runes) res = string(runes)
if i < size { if i < size {
w.continue_utf16 = size - i + 1 w.continue_utf16 = size - i + 1