]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[ldm] Add TODO and comment for segfaulting in compress function
authorStella Lau <laus@fb.com>
Thu, 13 Jul 2017 17:38:19 +0000 (10:38 -0700)
committerStella Lau <laus@fb.com>
Thu, 13 Jul 2017 17:38:19 +0000 (10:38 -0700)
contrib/long_distance_matching/ldm.c
contrib/long_distance_matching/main-ldm.c
contrib/long_distance_matching/util.c

index e64d28656789fbc9412a02535ea6a79146c8640d..7a54507326e3ece46ef184ff4c489137e080ddce 100644 (file)
@@ -28,7 +28,7 @@
 #define RUN_MASK ((1U<<RUN_BITS)-1)
 
 #define COMPUTE_STATS
-#define CHECKSUM_CHAR_OFFSET 2
+#define CHECKSUM_CHAR_OFFSET 0
 //#define RUN_CHECKS
 //#define LDM_DEBUG
 
@@ -470,7 +470,10 @@ static void outputBlock(LDM_CCtx *cctx,
   }
 }
 
-// TODO: srcSize and maxDstSize is unused
+// TODO: maxDstSize is unused. This function may seg fault when writing
+// beyond the size of dst, as it does not check maxDstSize. Writing to
+// a buffer and performing checks is a possible solution.
+//
 // This is based upon lz4.
 size_t LDM_compress(const void *src, size_t srcSize,
                     void *dst, size_t maxDstSize) {
index 8354b795ab98961c223365615dcfe5fdeff0abcc..9e7d452646349d4a96a7720f06bcea7e9f2276c3 100644 (file)
@@ -1,5 +1,3 @@
-// TODO: file size must fit into a U32
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include <fcntl.h>
 #include "ldm.h"
+#include "zstd.h"
 
 #define DEBUG
 //#define TEST
 
 /* Compress file given by fname and output to oname.
  * Returns 0 if successful, error code otherwise.
+ *
+ * TODO: This currently seg faults if the compressed size is > the decompress
+ * size due to the mmapping and output file size allocated to be the input size.
+ * The compress function should check before writing or buffer writes.
  */
 static int compress(const char *fname, const char *oname) {
   int fdin, fdout;
@@ -78,10 +81,9 @@ static int compress(const char *fname, const char *oname) {
            dst + LDM_HEADER_SIZE, statbuf.st_size);
 #endif
 */
-
   compressSize = LDM_HEADER_SIZE +
       LDM_compress(src, statbuf.st_size,
-                   dst + LDM_HEADER_SIZE, statbuf.st_size);
+                   dst + LDM_HEADER_SIZE, maxCompressSize);
 
   // Write compress and decompress size to header
   // TODO: should depend on LDM_DECOMPRESS_SIZE write32
index 6274921597d2634feff015c83419a1cefc57e082..47ac8a126b5737b943f642eba740d7c439450d47 100644 (file)
@@ -53,11 +53,6 @@ U32 LDM_read32(const void *ptr) {
   return *(const U32 *)ptr;
 }
 
-//TODO: endianness?
-void LDM_write64(void *memPtr, U64 value) {
-  memcpy(memPtr, &value, sizeof(value));
-}
-
 U64 LDM_read64(const void *ptr) {
   return *(const U64 *)ptr;
 }