From ec7912005a0ee4183652fdcf306881521b86f242 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 21 Sep 2018 14:53:13 -0400 Subject: [PATCH] Fix LZ4 decoding bug This was introduced in #170, but wasn't caught since emsdk didn't get rebuilt --- .circleci/config.yml | 4 ++-- emsdk/patches/lz4_c.patch | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d803cbf2e..5687916ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,7 +53,7 @@ jobs: - restore_cache: keys: - - v1-emsdk-{{ checksum "emsdk/Makefile" }}-v6- + - v1-emsdk-{{ checksum "emsdk/Makefile" }}-v7- - run: name: build @@ -68,7 +68,7 @@ jobs: paths: - ./emsdk/emsdk - ~/.ccache - key: v1-emsdk-{{ checksum "emsdk/Makefile" }}-v6-{{ .BuildNum }} + key: v1-emsdk-{{ checksum "emsdk/Makefile" }}-v7-{{ .BuildNum }} - persist_to_workspace: root: . diff --git a/emsdk/patches/lz4_c.patch b/emsdk/patches/lz4_c.patch index d85961ddd..f8d93eb57 100644 --- a/emsdk/patches/lz4_c.patch +++ b/emsdk/patches/lz4_c.patch @@ -52,7 +52,7 @@ index 4c3f583b7..5291002a4 100644 var contents = stream.node.contents; var compressedData = contents.compressedData; var written = 0; -@@ -122,6 +117,8 @@ mergeInto(LibraryManager.library, { +@@ -122,11 +117,14 @@ mergeInto(LibraryManager.library, { var chunkIndex = Math.floor(start / LZ4.CHUNK_SIZE); var compressedStart = compressedData.offsets[chunkIndex]; var compressedSize = compressedData.sizes[chunkIndex]; @@ -61,7 +61,13 @@ index 4c3f583b7..5291002a4 100644 var currChunk; if (compressedData.successes[chunkIndex]) { var found = compressedData.cachedIndexes.indexOf(chunkIndex); -@@ -138,18 +135,19 @@ mergeInto(LibraryManager.library, { + if (found >= 0) { + currChunk = compressedData.cachedChunks[found]; ++ buffer.set(Module.HEAPU8.subarray(currChunk + startInChunk, currChunk + endInChunk), offset + written); + } else { + // decompress the chunk + compressedData.cachedIndexes.pop(); +@@ -138,18 +136,19 @@ mergeInto(LibraryManager.library, { Module['decompressedChunks'] = (Module['decompressedChunks'] || 0) + 1; } var compressed = compressedData.data.subarray(compressedStart, compressedStart + compressedSize); @@ -89,7 +95,7 @@ index 4c3f583b7..5291002a4 100644 var currWritten = endInChunk - startInChunk; written += currWritten; } -@@ -181,4 +179,3 @@ if (LibraryManager.library['$FS__deps']) { +@@ -181,4 +180,3 @@ if (LibraryManager.library['$FS__deps']) { warn('FS does not seem to be in use (no preloaded files etc.), LZ4 will not do anything'); } #endif