Skip to content

Commit 14a4d3a

Browse files
Fix byte swapping in ms3_detect() for v3 records for big-endian systems. Fixes #120
1 parent 931aaf7 commit 14a4d3a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2025.303:
2+
- Fix byte swapping in ms3_detect() for v3 records for big-endian systems.
3+
14
2025.298: v3.1.10
25
- Add MSF_SPLITISVERSION flag to control using the splitversion value as the
36
version instead the record publication version for mstl3_addmsr() and variants.

parseutils.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,19 @@ ms3_detect (const char *record, uint64_t recbuflen, uint8_t *formatversion)
203203

204204
*formatversion = 3;
205205

206+
/* Check to see if byte swapping is needed, v3 is little-endian */
207+
swapflag = (ms_bigendianhost()) ? 1 : 0;
208+
206209
memcpy (&sidlength, pMS3FSDH_SIDLENGTH (record), sizeof (uint8_t));
207210
memcpy (&extralength, pMS3FSDH_EXTRALENGTH (record), sizeof (uint16_t));
208211
memcpy (&datalength, pMS3FSDH_DATALENGTH (record), sizeof (uint32_t));
209212

213+
if (swapflag)
214+
{
215+
ms_gswap2 (&extralength);
216+
ms_gswap4 (&datalength);
217+
}
218+
210219
reclen = MS3FSDH_LENGTH /* Length of fixed portion of header */
211220
+ sidlength /* Length of source identifier */
212221
+ extralength /* Length of extra headers */

0 commit comments

Comments
 (0)