Skip to content

Commit

Permalink
Fix misaligned address asan (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmooyyii authored Mar 2, 2024
1 parent 5529af4 commit 02e2c46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/streamvbyte_x64_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static size_t streamvbyte_encode_SSE41 (const uint32_t* in, uint32_t count, uint
uint32_t dw = in[i];
uint32_t symbol = (dw > 0x000000FF) + (dw > 0x0000FFFF) + (dw > 0x00FFFFFF);
key |= symbol << (i + i);
*((uint32_t*)dataPtr) = dw;
memcpy(dataPtr, &dw, 4);
dataPtr += 1 + symbol;
}
memcpy(keyPtr, &key, ((count & 7) + 3) >> 2);
Expand Down
23 changes: 23 additions & 0 deletions tests/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2759,8 +2759,31 @@ static bool issue42(void) {
return true;
}


static bool issue69(void) {
uint32_t N = 22;
uint32_t test_misaligned[22] = {
431, 292, 979, 994, 761, 879, 672, 690, 296,
931, 379, 98, 132, 105, 116, 841, 387, 831,
335, 333, 557, 915
};
uint32_t* datain = malloc(N * sizeof(uint32_t));
uint8_t* compressedbuffer = malloc(streamvbyte_max_compressedbytes(N));
uint32_t* recovdata = malloc(N * sizeof(uint32_t));
for (uint32_t k = 0; k < N; ++k) datain[k] = test_misaligned[k];
size_t compsize = streamvbyte_encode(datain, N, compressedbuffer); // encoding
// here the result is stored in compressedbuffer using compsize bytes
size_t compsize2 = streamvbyte_decode(compressedbuffer, recovdata, N); // decoding (fast)
if (compsize != compsize2) return false;
free(datain);
free(compressedbuffer);
free(recovdata);
return true;
}

int main(void) {
if (!issue42()) { printf("tests failed.\n"); return EXIT_FAILURE; }
if (!issue69()) { printf("tests failed.\n"); return EXIT_FAILURE; }
if (zigzagtests() == -1) { printf("tests failed.\n"); return EXIT_FAILURE; }
if (basictests() == -1) { printf("tests failed.\n"); return EXIT_FAILURE; }
if (aqrittests() == -1) { printf("tests failed.\n"); return EXIT_FAILURE; }
Expand Down

0 comments on commit 02e2c46

Please sign in to comment.