From 2856839d5d21e45da9cad9303dc2912d460337a3 Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Thu, 21 Apr 2022 11:32:44 +0200 Subject: [PATCH] DLog-specific tweaks to FastLZ * add a way to calculate the minimum compression output buffer size as required by the interface. This should've probably been baseline. * remove the unsafety compiler parameter because I don't want anybody to actually tweak it. Removing this safety check is still possible, but now somebody has to get his hands dirty and be aware of what the exact consequences are, as opposed to just tweaking what is essentially an opaque knob. * add a comment detailing whence the code was taken. Change-Id: I1229a9364523b3a5526c9933ccfd09d9292f34a9 Signed-off-by: Michal Bloch --- external/fastlz/fastlz.c | 16 +--------------- external/fastlz/fastlz.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/external/fastlz/fastlz.c b/external/fastlz/fastlz.c index f72a3d3..50946fc 100644 --- a/external/fastlz/fastlz.c +++ b/external/fastlz/fastlz.c @@ -1,6 +1,7 @@ /* FastLZ - Byte-aligned LZ77 compression library Copyright (C) 2005-2020 Ariya Hidayat + From https://github.com/ariya/FastLZ @ c3bdfad9e0094d0fb15c12cd300e647c13dc85f9 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,15 +27,6 @@ #include /* - * Always check for bound when decompressing. - * Generally it is best to leave it defined. - */ -#define FASTLZ_SAFE -#if defined(FASTLZ_USE_SAFE_DECOMPRESSOR) && (FASTLZ_USE_SAFE_DECOMPRESSOR == 0) -#undef FASTLZ_SAFE -#endif - -/* * Give hints to the compiler for branch prediction optimization. */ #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 2)) @@ -52,14 +44,8 @@ #define FLZ_ARCH64 #endif -#if defined(FASTLZ_SAFE) #define FASTLZ_BOUND_CHECK(cond) \ if (FASTLZ_UNLIKELY(!(cond))) return 0; -#else -#define FASTLZ_BOUND_CHECK(cond) \ - do { \ - } while (0) -#endif #if defined(FASTLZ_USE_MEMMOVE) && (FASTLZ_USE_MEMMOVE == 0) diff --git a/external/fastlz/fastlz.h b/external/fastlz/fastlz.h index 9172d74..b1b1cbc 100644 --- a/external/fastlz/fastlz.h +++ b/external/fastlz/fastlz.h @@ -1,6 +1,8 @@ /* FastLZ - Byte-aligned LZ77 compression library Copyright (C) 2005-2020 Ariya Hidayat + From https://github.com/ariya/FastLZ @ c3bdfad9e0094d0fb15c12cd300e647c13dc85f9 + With minor modifications (C) 2022, Samsung Electronics Co., Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -32,6 +34,15 @@ #define FASTLZ_VERSION_STRING "0.5.0" +/* DLog addition. Output always has to be larger than input, in case of FastLZ + * at least by 5%, with a minimum of 66 bytes. This is because compression can + * fail if data isn't compressible, such as if you try to compress compressed + * data, but usually the actual output will be just a fraction of the buffer. */ +#define FASTLZ_NEEDED_OUTPUT_SIZE(size) ({ \ + size_t _plus_5_percent = (size) * 1.05 + 1; \ + _plus_5_percent > 66 ? _plus_5_percent : 66; \ +}) + #if defined(__cplusplus) extern "C" { #endif -- 2.7.4