Skip to content

Commit 2a097e9

Browse files
committed
Fix #54391: Invalid pointer aliasing in SAS7BDAT parser
1 parent 92d1d6a commit 2a097e9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pandas/_libs/byteswap.pyx

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from libc.stdint cimport (
1010
uint32_t,
1111
uint64_t,
1212
)
13+
from libc.string cimport memcpy
1314

1415

1516
def read_float_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):
@@ -82,12 +83,14 @@ cdef extern from *:
8283

8384

8485
cdef float _byteswap_float(float num):
85-
cdef uint32_t *intptr = <uint32_t *>&num
86-
intptr[0] = _byteswap4(intptr[0])
87-
return num
86+
cdef uint32_t num_uint
87+
memcpy(&num_uint, &num, sizeof(float))
88+
num_uint = _byteswap4(num_uint)
89+
return (<float *>&num_uint)[0]
8890

8991

9092
cdef double _byteswap_double(double num):
91-
cdef uint64_t *intptr = <uint64_t *>&num
92-
intptr[0] = _byteswap8(intptr[0])
93-
return num
93+
cdef uint64_t num_uint
94+
memcpy(&num_uint, &num, sizeof(double))
95+
num_uint = _byteswap8(num_uint)
96+
return (<double *>&num_uint)[0]

0 commit comments

Comments
 (0)