Skip to content

Commit

Permalink
Enforce ERR_NX_TPBC_GT_SPBC in deflate on more cases
Browse files Browse the repository at this point in the history
After libnxz started to use the history when compressing data,
cc = ERR_NX_TPBC_GT_SPBC was not returned all the times it was
expected. That happens because the NX considers SPBC to be a sum of the
amount of input bytes processed plus the length of the history.

Meanwhile, in order to detect ERR_NX_TPBC_GT_SPBC, the length of the
history should not be included in SPBC.

Fixes issue #161.

Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
  • Loading branch information
tuliom committed May 5, 2022
1 parent caffcc0 commit 8b7616b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/nx_deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
#include "nx_dbg.h"
#include "nx_dht.h"

/** @file nx_deflate.c
* \brief Implement the deflate function for the NX GZIP accelerator and
* related functions.
*/

#define DEF_MEM_LEVEL 8
#define nx_deflateInit(strm, level) nx_deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))

Expand Down Expand Up @@ -1252,6 +1257,23 @@ static int nx_compress_block(nx_streamp s, int fc, int limit)
cc = nx_submit_job(ddl_in, ddl_out, nxcmdp, s->nxdevp);
s->nx_cc = cc;

/** The NX GZIP does not subtract the history length from SPBC when
* checking for ERR_NX_TPBC_GT_SPBC. So, there are some scenarios
* where the length of the output is larger than the input, but the
* NX GZIP can't see this. This is particularly critical when the input
* length is < 32KiB. So, we have to check for this scenario and fix
* the result in order to generate better results.
*/
if (!cc) {
uint32_t histlen = getnn(s->nxcmdp->cpb, in_histlen)
* sizeof(nx_qw_t);
uint32_t spbc = get_spbc(s, fc);
uint32_t tpbc = get32(s->nxcmdp->crb.csb, tpbc);

if (tpbc + histlen > spbc)
cc = ERR_NX_TPBC_GT_SPBC;
}

if (s->dry_run && (cc == ERR_NX_TPBC_GT_SPBC || cc == ERR_NX_OK)) {
/* only needed for sampling LZcounts (symbol stats) */
s->dry_run = 0;
Expand Down

0 comments on commit 8b7616b

Please sign in to comment.