Skip to content

Commit aad156b

Browse files
committed
HD-4220: fix concurrency potential bug
1 parent 95770dc commit aad156b

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

backend.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ bool check_matrix_fragment(char *frag, int frag_len, int piecesize) {
100100
size_t offset = 0;
101101

102102
while (offset < frag_len) {
103+
if (offset + sizeof(fragment_header_t) > frag_len) {
104+
// there is some remaining bytes, but not enough to read at least the header
105+
return false;
106+
}
103107
if (is_invalid_fragment_header((fragment_header_t *)&frag[offset])) {
104108
return false;
105109
}
106-
offset += piecesize + getHeaderSize();
110+
offset += ((fragment_header_t *)&frag[offset])->meta.size + getHeaderSize();
107111
}
108112

109113
return true;

backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (backend *Backend) EncodeMatrixWithBufferMatrix(bm *BufferMatrix, chunkSize
282282
go func(nth int) {
283283
fragLen := C.size_t(chunkSize)
284284
// last subgroup has a different size
285-
if i == int(ctx.number_of_subgroup)-1 {
285+
if nth == int(ctx.number_of_subgroup)-1 {
286286
fragLen = C.size_t(bm.FragLenLastSubGroup())
287287
}
288288
atomic.AddInt64(&totLen, int64(fragLen)+int64(backend.headerSize))
@@ -690,7 +690,7 @@ func (backend *Backend) GetRangeMatrix(startIncl, endIncl, cellDataSize, fragSiz
690690
all fragments (see (2) in the function's comment above). */
691691
linearizedRangeStartIncl := startIncl - dataOffset
692692

693-
/* Decoding always works on a group boundary. */
693+
/* Decoding always works on a column boundary. */
694694
decodedRangeStartIncl := startIncl - lineStart*lineSize
695695

696696
return &RangeMatrix{

backend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ func TestLinearizeMatrixAndReconstruct(t *testing.T) {
913913
frags2 = append(frags2, encoded.Data[i][rangeM.InFragRangeStartIncl:rangeM.InFragRangeEndExcl])
914914
}
915915

916-
// now do the same test, but this time, insted of linearizing, we are going to reconstruct the stripes
916+
// now do the same test, but this time, instead of linearizing, we are going to reconstruct the stripes
917917
reconstructed, err := backend.ReconstructMatrix(frags2[1:], 0, currentChunkSize)
918918

919919
require.NoError(t, err)

0 commit comments

Comments
 (0)