better error handling for zstddec-tar1090
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
+
|
||||
+/*
|
||||
+ * findDecompressedSize interface changed from unsigned long long to size_t for wasm / browser compatibility (matthias.wirth@gmail.com)
|
||||
+ * 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
|
||||
+ */
|
||||
@@ -19,7 +19,7 @@
|
||||
* 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 size_t 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
|
||||
@@ -28,11 +28,11 @@
|
||||
* skippable frames
|
||||
* @return : decompressed size of the frames contained */
|
||||
-unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize)
|
||||
+size_t ZSTD_findDecompressedSize(const void* src, size_t srcSize)
|
||||
+U32 ZSTD_findDecompressedSize(const void* src, size_t srcSize)
|
||||
{
|
||||
unsigned long long totalDstSize = 0;
|
||||
|
||||
+ size_t _error = 0;
|
||||
+ U32 _error = 0xffffffff;
|
||||
+
|
||||
while (srcSize >= ZSTD_startingInputLength(ZSTD_f_zstd1)) {
|
||||
U32 const magicNumber = MEM_readLE32(src);
|
||||
@@ -69,10 +69,10 @@
|
||||
} /* while (srcSize >= ZSTD_frameHeaderSize_prefix) */
|
||||
|
||||
- if (srcSize) return ZSTD_CONTENTSIZE_ERROR;
|
||||
+ if (totalDstSize > UINT32_MAX || srcSize) return _error;
|
||||
+ if (totalDstSize >= UINT32_MAX || srcSize) return _error;
|
||||
|
||||
- return totalDstSize;
|
||||
+ return (size_t) totalDstSize;
|
||||
+ return (U32) totalDstSize;
|
||||
}
|
||||
|
||||
/** ZSTD_getDecompressedSize() :
|
||||
|
||||
Reference in New Issue
Block a user