--- /tmp/zstd-1.5.0/build/single_file_libs/zstddeclib.c 2022-07-19 08:40:31.371785257 +0200 +++ zstddec/zstddeclib.c 2022-07-19 08:52:36.644646467 +0200 @@ -16,6 +16,13 @@ * in the COPYING file in the root directory of this source tree). * You may select, at your option, one of the above-listed licenses. */ + +/* + * findDecompressedSize interface changed from unsigned long long to U32 for wasm / browser compatibility (matthias.wirth@gmail.com) + * further info on the issue: https://github.com/WebAssembly/WASI/issues/54 + * This is not necessary for browsers after 2020, but there are still plenty of older devices around + */ + /* * Settings to bake for the standalone decompressor. * @@ -4937,7 +4944,7 @@ * note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to * read each contained frame header. This is fast as most of the data is skipped, * however it does mean that all frame data must be present and valid. */ -ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize); +ZSTDLIB_API U32 ZSTD_findDecompressedSize(const void* src, size_t srcSize); /*! ZSTD_decompressBound() : * `src` should point to the start of a series of ZSTD encoded and/or skippable frames @@ -11974,17 +11981,19 @@ * `srcSize` must be the exact length of some number of ZSTD compressed and/or * skippable frames * @return : decompressed size of the frames contained */ -unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize) +U32 ZSTD_findDecompressedSize(const void* src, size_t srcSize) { unsigned long long totalDstSize = 0; + U32 _error = 0xffffffff; + while (srcSize >= ZSTD_startingInputLength(ZSTD_f_zstd1)) { U32 const magicNumber = MEM_readLE32(src); if ((magicNumber & ZSTD_MAGIC_SKIPPABLE_MASK) == ZSTD_MAGIC_SKIPPABLE_START) { size_t const skippableSize = readSkippableFrameSize(src, srcSize); if (ZSTD_isError(skippableSize)) { - return ZSTD_CONTENTSIZE_ERROR; + return _error; } assert(skippableSize <= srcSize); @@ -11994,15 +12003,15 @@ } { unsigned long long const ret = ZSTD_getFrameContentSize(src, srcSize); - if (ret >= ZSTD_CONTENTSIZE_ERROR) return ret; + if (ret >= ZSTD_CONTENTSIZE_ERROR) return _error; /* check for overflow */ - if (totalDstSize + ret < totalDstSize) return ZSTD_CONTENTSIZE_ERROR; + if (totalDstSize + ret < totalDstSize) return _error; totalDstSize += ret; } { size_t const frameSrcSize = ZSTD_findFrameCompressedSize(src, srcSize); if (ZSTD_isError(frameSrcSize)) { - return ZSTD_CONTENTSIZE_ERROR; + return _error; } src = (const BYTE *)src + frameSrcSize; @@ -12010,9 +12019,9 @@ } } /* while (srcSize >= ZSTD_frameHeaderSize_prefix) */ - if (srcSize) return ZSTD_CONTENTSIZE_ERROR; + if (totalDstSize >= UINT32_MAX || srcSize) return _error; - return totalDstSize; + return (U32) totalDstSize; } /** ZSTD_getDecompressedSize() :