265 lines
5.8 KiB
Diff
265 lines
5.8 KiB
Diff
diff '--color=auto' -urN tinf-clean/tinf.h decompressor/tinf/tinf.h
|
|
--- tinf-clean/tinf.h 2023-06-06 00:57:04.683481827 +0200
|
|
+++ decompressor/tinf/tinf.h 2023-06-06 00:56:14.485629430 +0200
|
|
@@ -59,7 +59,9 @@
|
|
*
|
|
* @deprecated No longer required, may be removed in a future version.
|
|
*/
|
|
+/*
|
|
void TINFCC tinf_init(void);
|
|
+*/
|
|
|
|
/**
|
|
* Decompress `sourceLen` bytes of deflate data from `source` to `dest`.
|
|
@@ -76,7 +78,7 @@
|
|
* @param sourceLen size of compressed data
|
|
* @return `TINF_OK` on success, error code on error
|
|
*/
|
|
-int TINFCC tinf_uncompress(void *dest, unsigned int *destLen,
|
|
+int TINFCC tinf_uncompress(void *dest,
|
|
const void *source, unsigned int sourceLen);
|
|
|
|
/**
|
|
@@ -94,7 +96,7 @@
|
|
* @param sourceLen size of compressed data
|
|
* @return `TINF_OK` on success, error code on error
|
|
*/
|
|
-int TINFCC tinf_gzip_uncompress(void *dest, unsigned int *destLen,
|
|
+int TINFCC tinf_gzip_uncompress(void *dest,
|
|
const void *source, unsigned int sourceLen);
|
|
|
|
/**
|
|
@@ -112,8 +114,10 @@
|
|
* @param sourceLen size of compressed data
|
|
* @return `TINF_OK` on success, error code on error
|
|
*/
|
|
+/*
|
|
int TINFCC tinf_zlib_uncompress(void *dest, unsigned int *destLen,
|
|
const void *source, unsigned int sourceLen);
|
|
+*/
|
|
|
|
/**
|
|
* Compute Adler-32 checksum of `length` bytes starting at `data`.
|
|
@@ -122,7 +126,9 @@
|
|
* @param length size of data
|
|
* @return Adler-32 checksum
|
|
*/
|
|
+/*
|
|
unsigned int TINFCC tinf_adler32(const void *data, unsigned int length);
|
|
+*/
|
|
|
|
/**
|
|
* Compute CRC32 checksum of `length` bytes starting at `data`.
|
|
@@ -131,7 +137,9 @@
|
|
* @param length size of data
|
|
* @return CRC32 checksum
|
|
*/
|
|
+/*
|
|
unsigned int TINFCC tinf_crc32(const void *data, unsigned int length);
|
|
+*/
|
|
|
|
#ifdef __cplusplus
|
|
} /* extern "C" */
|
|
diff '--color=auto' -urN tinf-clean/tinfgzip.c decompressor/tinf/tinfgzip.c
|
|
--- tinf-clean/tinfgzip.c 2023-06-06 00:57:16.983772372 +0200
|
|
+++ decompressor/tinf/tinfgzip.c 2023-06-06 01:09:39.119942087 +0200
|
|
@@ -39,6 +39,8 @@
|
|
| ((unsigned int) p[1] << 8);
|
|
}
|
|
|
|
+/*
|
|
+
|
|
static unsigned int read_le32(const unsigned char *p)
|
|
{
|
|
return ((unsigned int) p[0])
|
|
@@ -47,13 +49,17 @@
|
|
| ((unsigned int) p[3] << 24);
|
|
}
|
|
|
|
-int tinf_gzip_uncompress(void *dest, unsigned int *destLen,
|
|
+*/
|
|
+
|
|
+int tinf_gzip_uncompress(void *dest,
|
|
const void *source, unsigned int sourceLen)
|
|
{
|
|
const unsigned char *src = (const unsigned char *) source;
|
|
unsigned char *dst = (unsigned char *) dest;
|
|
const unsigned char *start;
|
|
+/*
|
|
unsigned int dlen, crc32;
|
|
+*/
|
|
int res;
|
|
unsigned char flg;
|
|
|
|
@@ -101,7 +107,7 @@
|
|
/* Skip file name if present */
|
|
if (flg & FNAME) {
|
|
do {
|
|
- if (start - src >= sourceLen) {
|
|
+ if (((unsigned int)(start - src)) >= sourceLen) {
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
} while (*start++);
|
|
@@ -110,7 +116,7 @@
|
|
/* Skip file comment if present */
|
|
if (flg & FCOMMENT) {
|
|
do {
|
|
- if (start - src >= sourceLen) {
|
|
+ if (((unsigned int)(start - src)) >= sourceLen) {
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
} while (*start++);
|
|
@@ -118,6 +124,7 @@
|
|
|
|
/* Check header crc if present */
|
|
if (flg & FHCRC) {
|
|
+/*
|
|
unsigned int hcrc;
|
|
|
|
if (start - src > sourceLen - 2) {
|
|
@@ -129,10 +136,12 @@
|
|
if (hcrc != (tinf_crc32(src, start - src) & 0x0000FFFF)) {
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
+*/
|
|
|
|
start += 2;
|
|
}
|
|
|
|
+#if 0
|
|
/* -- Get decompressed length -- */
|
|
|
|
dlen = read_le32(&src[sourceLen - 4]);
|
|
@@ -144,6 +153,7 @@
|
|
/* -- Get CRC32 checksum of original data -- */
|
|
|
|
crc32 = read_le32(&src[sourceLen - 8]);
|
|
+#endif
|
|
|
|
/* -- Decompress data -- */
|
|
|
|
@@ -151,13 +161,14 @@
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
|
|
- res = tinf_uncompress(dst, destLen, start,
|
|
+ res = tinf_uncompress(dst, start,
|
|
(src + sourceLen) - start - 8);
|
|
|
|
if (res != TINF_OK) {
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
|
|
+#if 0
|
|
if (*destLen != dlen) {
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
@@ -167,6 +178,7 @@
|
|
if (crc32 != tinf_crc32(dst, dlen)) {
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
+#endif
|
|
|
|
return TINF_OK;
|
|
}
|
|
diff '--color=auto' -urN tinf-clean/tinflate.c decompressor/tinf/tinflate.c
|
|
--- tinf-clean/tinflate.c 2023-06-06 00:57:10.746958386 +0200
|
|
+++ decompressor/tinf/tinflate.c 2023-06-06 01:12:19.629674294 +0200
|
|
@@ -25,7 +25,7 @@
|
|
|
|
#include "tinf.h"
|
|
|
|
-#include <assert.h>
|
|
+#define assert(...)
|
|
#include <limits.h>
|
|
|
|
#if defined(UINT_MAX) && (UINT_MAX) < 0xFFFFFFFFUL
|
|
@@ -49,7 +49,9 @@
|
|
|
|
unsigned char *dest_start;
|
|
unsigned char *dest;
|
|
+/*
|
|
unsigned char *dest_end;
|
|
+*/
|
|
|
|
struct tinf_tree ltree; /* Literal/length tree */
|
|
struct tinf_tree dtree; /* Distance tree */
|
|
@@ -425,9 +427,12 @@
|
|
}
|
|
|
|
if (sym < 256) {
|
|
+/*
|
|
if (d->dest == d->dest_end) {
|
|
return TINF_BUF_ERROR;
|
|
}
|
|
+*/
|
|
+
|
|
*d->dest++ = sym;
|
|
}
|
|
else {
|
|
@@ -465,9 +470,11 @@
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
|
|
+/*
|
|
if (d->dest_end - d->dest < length) {
|
|
return TINF_BUF_ERROR;
|
|
}
|
|
+*/
|
|
|
|
/* Copy match */
|
|
for (i = 0; i < length; ++i) {
|
|
@@ -501,6 +508,7 @@
|
|
|
|
d->source += 4;
|
|
|
|
+/*
|
|
if (d->source_end - d->source < length) {
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
@@ -508,6 +516,7 @@
|
|
if (d->dest_end - d->dest < length) {
|
|
return TINF_BUF_ERROR;
|
|
}
|
|
+*/
|
|
|
|
/* Copy block */
|
|
while (length--) {
|
|
@@ -548,13 +557,15 @@
|
|
/* -- Public functions -- */
|
|
|
|
/* Initialize global (static) data */
|
|
+/*
|
|
void tinf_init(void)
|
|
{
|
|
return;
|
|
}
|
|
+*/
|
|
|
|
/* Inflate stream from source to dest */
|
|
-int tinf_uncompress(void *dest, unsigned int *destLen,
|
|
+int tinf_uncompress(void *dest,
|
|
const void *source, unsigned int sourceLen)
|
|
{
|
|
struct tinf_data d;
|
|
@@ -569,7 +580,9 @@
|
|
|
|
d.dest = (unsigned char *) dest;
|
|
d.dest_start = d.dest;
|
|
+/*
|
|
d.dest_end = d.dest + *destLen;
|
|
+*/
|
|
|
|
do {
|
|
unsigned int btype;
|
|
@@ -610,7 +623,9 @@
|
|
return TINF_DATA_ERROR;
|
|
}
|
|
|
|
+/*
|
|
*destLen = d.dest - d.dest_start;
|
|
+*/
|
|
|
|
return TINF_OK;
|
|
}
|