Skip to content

Commit 39c2d7b

Browse files
committed
Fix array size allocate overflow
- Upgrade the dependencies package version
1 parent 336f5ed commit 39c2d7b

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/xuri/excelize-py
33
go 1.20
44

55
require (
6-
github.com/xuri/excelize/v2 v2.9.1-0.20250208014036-718417e15ed6
6+
github.com/xuri/excelize/v2 v2.9.1-0.20250219061259-52642854413f
77
golang.org/x/image v0.24.0
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ github.com/tiendc/go-deepcopy v1.5.0 h1:TbtS9hclrKZcF1AHby8evDm4mIQU36i6tSYuvx/T
1010
github.com/tiendc/go-deepcopy v1.5.0/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
1111
github.com/xuri/efp v0.0.0-20241211021726-c4e992084aa6 h1:8m6DWBG+dlFNbx5ynvrE7NgI+Y7OlZVMVTpayoW+rCc=
1212
github.com/xuri/efp v0.0.0-20241211021726-c4e992084aa6/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
13-
github.com/xuri/excelize/v2 v2.9.1-0.20250208014036-718417e15ed6 h1:fT911cTvmhbFNfEhUjz5hY0tcXEedJyx1HkwhOQcm3s=
14-
github.com/xuri/excelize/v2 v2.9.1-0.20250208014036-718417e15ed6/go.mod h1:QPDLfWgowGnzIqBhd8g4iNoymgms2UL7Ok/Qm/NSPsg=
13+
github.com/xuri/excelize/v2 v2.9.1-0.20250219061259-52642854413f h1:6r2z3li0dWKGsis3HqEsZnEb/FKq/AE88eBwV4zMkog=
14+
github.com/xuri/excelize/v2 v2.9.1-0.20250219061259-52642854413f/go.mod h1:pLb4VqhRJ56LzWGi1Oa30+VQ4Jbmn8kbPLfiwAvBuCA=
1515
github.com/xuri/nfp v0.0.0-20250111060730-82a408b9aa71 h1:hOh7aVDrvGJRxzXrQbDY8E+02oaI//5cHL+97oYpEPw=
1616
github.com/xuri/nfp v0.0.0-20250111060730-82a408b9aa71/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
1717
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=

main.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,13 +1071,12 @@ func GetCellRichText(idx int, sheet, cell *C.char) C.struct_GetCellRichTextResul
10711071
return C.struct_GetCellRichTextResult{Err: C.CString(err.Error())}
10721072
}
10731073
cArray := C.malloc(C.size_t(len(runs)) * C.size_t(unsafe.Sizeof(C.struct_RichTextRun{})))
1074-
cStructArray := (*[1 << 30]C.struct_RichTextRun)(cArray)[:len(runs):len(runs)]
10751074
for i, r := range runs {
10761075
cVal, err := goValueToC(reflect.ValueOf(r), reflect.ValueOf(&C.struct_RichTextRun{}))
10771076
if err != nil {
10781077
return C.struct_GetCellRichTextResult{Err: C.CString(err.Error())}
10791078
}
1080-
cStructArray[i] = cVal.Elem().Interface().(C.struct_RichTextRun)
1079+
*(*C.struct_RichTextRun)(unsafe.Pointer(uintptr(unsafe.Pointer(cArray)) + uintptr(i)*unsafe.Sizeof(C.struct_RichTextRun{}))) = cVal.Elem().Interface().(C.struct_RichTextRun)
10811080
}
10821081
return C.struct_GetCellRichTextResult{RunsLen: C.int(len(runs)), Runs: (*C.struct_RichTextRun)(cArray), Err: C.CString(emptyString)}
10831082
}
@@ -1332,13 +1331,12 @@ func GetTables(idx int, sheet *C.char) C.struct_GetTablesResult {
13321331
return C.struct_GetTablesResult{Err: C.CString(err.Error())}
13331332
}
13341333
cArray := C.malloc(C.size_t(len(tables)) * C.size_t(unsafe.Sizeof(C.struct_Table{})))
1335-
cStructArray := (*[1 << 30]C.struct_Table)(cArray)[:len(tables):len(tables)]
13361334
for i, t := range tables {
13371335
cVal, err := goValueToC(reflect.ValueOf(t), reflect.ValueOf(&C.struct_Table{}))
13381336
if err != nil {
13391337
return C.struct_GetTablesResult{Err: C.CString(err.Error())}
13401338
}
1341-
cStructArray[i] = cVal.Elem().Interface().(C.struct_Table)
1339+
*(*C.struct_Table)(unsafe.Pointer(uintptr(unsafe.Pointer(cArray)) + uintptr(i)*unsafe.Sizeof(C.struct_Table{}))) = cVal.Elem().Interface().(C.struct_Table)
13421340
}
13431341
return C.struct_GetTablesResult{TablesLen: C.int(len(tables)), Tables: (*C.struct_Table)(cArray), Err: C.CString(emptyString)}
13441342
}
@@ -1915,9 +1913,8 @@ func SearchSheet(idx int, sheet, value *C.char, reg bool) C.struct_StringArrayEr
19151913
return C.struct_StringArrayErrorResult{Err: C.CString(err.Error())}
19161914
}
19171915
cArray := C.malloc(C.size_t(len(result)) * C.size_t(unsafe.Sizeof(uintptr(0))))
1918-
cArrayPtr := (*[1 << 30]*C.char)(cArray)
19191916
for i, v := range result {
1920-
cArrayPtr[i] = C.CString(v)
1917+
*(*unsafe.Pointer)(unsafe.Pointer(uintptr(unsafe.Pointer(cArray)) + uintptr(i)*unsafe.Sizeof(uintptr(0)))) = unsafe.Pointer(C.CString(v))
19211918
}
19221919
return C.struct_StringArrayErrorResult{ArrLen: C.int(len(result)), Arr: (**C.char)(cArray), Err: C.CString(emptyString)}
19231920
}

0 commit comments

Comments
 (0)