1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
From: Ying-Chun Liu (PaulLiu)
Description: Fix CRC32 endian
The patch fixes crc32 function wrong result on s390x (big-endian machines).
Bug-Debian: https://bugs.debian.org/1087142
Last-Update: 2025-04-15
Index: tl-parser-0.0.0+git20210107.1933e76f/crc32.c
===================================================================
--- tl-parser-0.0.0+git20210107.1933e76f.orig/crc32.c
+++ tl-parser-0.0.0+git20210107.1933e76f/crc32.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <math.h>
#include <assert.h>
+#include <endian.h>
#include "crc32.h"
@@ -300,7 +301,7 @@ unsigned int crc32_table0[256] = {
static unsigned int crc32_partial (const void *data, int len, unsigned crc) {
const int *p = (const int *) data;
int x;
-#define DO_ONE(v) crc ^= v; crc = crc32_table0[crc & 0xff] ^ crc32_table1[(crc & 0xff00) >> 8] ^ crc32_table2[(crc & 0xff0000) >> 16] ^ crc32_table[crc >> 24];
+#define DO_ONE(v) crc ^= le32toh(v); crc = crc32_table0[crc & 0xff] ^ crc32_table1[(crc & 0xff00) >> 8] ^ crc32_table2[(crc & 0xff0000) >> 16] ^ crc32_table[crc >> 24];
#define DO_FOUR(p) DO_ONE((p)[0]); DO_ONE((p)[1]); DO_ONE((p)[2]); DO_ONE((p)[3]);
for (x = (len >> 5); x > 0; x--) {
|