Skip to content

Commit

Permalink
fix ub in shuffle and unshuffle by marking _dst non-const
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilDohne authored and FrancescAlted committed Oct 23, 2024
1 parent f8723dc commit 58ab7f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions blosc/shuffle.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@


/* Define function pointer types for shuffle/unshuffle routines. */
typedef void(* shuffle_func)(const int32_t, const int32_t, const uint8_t*, const uint8_t*);
typedef void(* unshuffle_func)(const int32_t, const int32_t, const uint8_t*, const uint8_t*);
typedef void(* shuffle_func)(const int32_t, const int32_t, const uint8_t*, uint8_t*);
typedef void(* unshuffle_func)(const int32_t, const int32_t, const uint8_t*, uint8_t*);
// For bitshuffle, everything is done in terms of size_t and int64_t (return value)
// and although this is not strictly necessary for Blosc, it does not hurt either
typedef int64_t(* bitshuffle_func)(const void*, void*, const size_t, const size_t);
Expand Down Expand Up @@ -419,7 +419,7 @@ void init_shuffle_implementation(void) {
hardware-accelerated routine at run-time. */
void
shuffle(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t* _src, const uint8_t* _dest) {
const uint8_t* _src, uint8_t* _dest) {
/* Initialize the shuffle implementation if necessary. */
init_shuffle_implementation();

Expand All @@ -432,7 +432,7 @@ shuffle(const int32_t bytesoftype, const int32_t blocksize,
hardware-accelerated routine at run-time. */
void
unshuffle(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t* _src, const uint8_t* _dest) {
const uint8_t* _src, uint8_t* _dest) {
/* Initialize the shuffle implementation if necessary. */
init_shuffle_implementation();

Expand All @@ -445,7 +445,7 @@ unshuffle(const int32_t bytesoftype, const int32_t blocksize,
hardware-accelerated routine at run-time. */
int32_t
bitshuffle(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, const uint8_t *_dest) {
const uint8_t *_src, uint8_t *_dest) {
/* Initialize the shuffle implementation if necessary. */
init_shuffle_implementation();
size_t size = blocksize / bytesoftype;
Expand All @@ -469,7 +469,7 @@ bitshuffle(const int32_t bytesoftype, const int32_t blocksize,
/* Bit-unshuffle a block by dynamically dispatching to the appropriate
hardware-accelerated routine at run-time. */
int32_t bitunshuffle(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, const uint8_t *_dest,
const uint8_t *_src, uint8_t *_dest,
const uint8_t format_version) {
/* Initialize the shuffle implementation if necessary. */
init_shuffle_implementation();
Expand Down
8 changes: 4 additions & 4 deletions blosc/shuffle.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
*/
BLOSC_NO_EXPORT void
shuffle(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t* _src, const uint8_t* _dest);
uint8_t* _src, const uint8_t* _dest);

BLOSC_NO_EXPORT int32_t
bitshuffle(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, const uint8_t *_dest);
const uint8_t *_src, uint8_t *_dest);

/**
Primary unshuffle and bitunshuffle routine.
Expand All @@ -53,12 +53,12 @@ BLOSC_NO_EXPORT int32_t
*/
BLOSC_NO_EXPORT void
unshuffle(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t* _src, const uint8_t* _dest);
uint8_t* _src, const uint8_t* _dest);


BLOSC_NO_EXPORT int32_t
bitunshuffle(const int32_t bytesoftype, const int32_t blocksize,
const uint8_t *_src, const uint8_t *_dest,
const uint8_t *_src, uint8_t *_dest,
const uint8_t format_version);

#endif /* BLOSC_SHUFFLE_H */

0 comments on commit 58ab7f5

Please sign in to comment.