Skip to content

Commit

Permalink
Fix the bug of out-of-bound write (#10257)
Browse files Browse the repository at this point in the history
* Fix the bug of out-of-bound write
* remove cgo dependencies, cgo and recover do not work together, I will subsequently remove all cgo's from make

Approved by: @aunjgr, @fengttt
  • Loading branch information
nnsgmsone authored Jun 27, 2023
1 parent 8eb3e30 commit dacfe86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 12 additions & 4 deletions pkg/common/hashmap/inthashmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,19 @@ func fillKeys[T types.FixedSizeT](m *IntHashMap, vec *vector.Vector, size uint32
}
} else if vec.IsConst() {
ptr := (*T)(vector.GetPtrAt(vec, 0))
for i := 0; i < n; i++ {
*(*int8)(unsafe.Add(unsafe.Pointer(&keys[i]), keyOffs[i])) = 0
*(*T)(unsafe.Add(unsafe.Pointer(&keys[i]), keyOffs[i]+1)) = *ptr
// The old code was too stupid and would lead to out-of-bounds writing
if m.hasNull {
for i := 0; i < n; i++ {
*(*T)(unsafe.Add(unsafe.Pointer(&keys[i]), keyOffs[i])) = *ptr
}
uint32AddScalar(1+size, keyOffs[:n], keyOffs[:n])
} else {
for i := 0; i < n; i++ {
*(*int8)(unsafe.Add(unsafe.Pointer(&keys[i]), keyOffs[i])) = 0
*(*T)(unsafe.Add(unsafe.Pointer(&keys[i]), keyOffs[i]+1)) = *ptr
}
uint32AddScalar(size, keyOffs[:n], keyOffs[:n])
}
uint32AddScalar(size, keyOffs[:n], keyOffs[:n])
} else if !vec.GetNulls().Any() {
if m.hasNull {
for i := 0; i < n; i++ {
Expand Down
7 changes: 0 additions & 7 deletions pkg/vectorize/sum/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@

package sum

/*
#include "mo.h"
#cgo CFLAGS: -I../../../cgo
#cgo LDFLAGS: -L../../../cgo -lmo -lm
*/
import "C"

import (
"github.com/matrixorigin/matrixone/pkg/container/nulls"
"github.com/matrixorigin/matrixone/pkg/container/types"
Expand Down

0 comments on commit dacfe86

Please sign in to comment.