aboutsummaryrefslogtreecommitdiffstats
path: root/community/sox/sox-14.4.2-hcom_stopwrite_big_endian_bug_fix.patch
blob: 9aa82064718664c8991174be3bdf34c8630be13b (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
diff --git a/src/hcom.c b/src/hcom.c
index e76820e..fb8de99 100644
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -428,12 +428,19 @@ static int stopwrite(sox_format_t * ft)
 {
   priv_t *p = (priv_t *) ft->priv;
   unsigned char *compressed_data = p->data;
-  size_t compressed_len = p->pos;
+  int32_t compressed_len = (int32_t)p->pos;
   int rc = SOX_SUCCESS;
 
+  if (p->pos >> 32 > 0)
+    lsx_warn(
+      "%s: possible data loss"
+      " (the size of data to be written has exceeded its limit)",
+      ft->filename
+    );
+
   /* Compress it all at once */
   if (compressed_len)
-    compress(ft, &compressed_data, (int32_t *)&compressed_len);
+    compress(ft, &compressed_data, &compressed_len);
   free(p->data);
 
   /* Write the header */
@@ -447,7 +454,7 @@ static int stopwrite(sox_format_t * ft)
   if (lsx_error(ft)) {
     lsx_fail_errno(ft, errno, "write error in HCOM header");
     rc = SOX_EOF;
-  } else if (lsx_writebuf(ft, compressed_data, compressed_len) != compressed_len) {
+  } else if (lsx_writebuf(ft, compressed_data, (size_t) compressed_len) != (size_t) compressed_len) {
     /* Write the compressed_data fork */
     lsx_fail_errno(ft, errno, "can't write compressed HCOM data");
     rc = SOX_EOF;
@@ -456,7 +463,7 @@ static int stopwrite(sox_format_t * ft)
 
   if (rc == SOX_SUCCESS)
     /* Pad the compressed_data fork to a multiple of 128 bytes */
-    lsx_padbytes(ft, 128u - (compressed_len % 128));
+    lsx_padbytes(ft, (size_t) 128 - (compressed_len % 128));
 
   return rc;
 }