Fix error when decompressing short content

This commit is contained in:
Mikko Ahlroth 2022-10-29 00:16:13 +03:00
parent 90aaa894c8
commit 025fa41ea8
2 changed files with 8 additions and 2 deletions

View file

@ -35,7 +35,7 @@
<div id="length">Waiting...</div>
<div id="info">
v2.0.2 | © Nicd 2022 | <a href="https://gitlab.com/Nicd/tahnaroskakori" target="_blank">Source</a> | <a
v2.0.3 | © Nicd 2022 | <a href="https://gitlab.com/Nicd/tahnaroskakori" target="_blank">Source</a> | <a
href="./licenses.txt" target="_blank">Licenses</a>
</div>
</footer>

View file

@ -158,6 +158,12 @@ async function syncCompress() {
* the user being zip bombed with a short hash that generates gigabytes of output.
*/
async function streamDecompress() {
if (window.location.hash.length <= 1) {
currentCode = "";
renderCode();
return;
}
try {
const data = BASECODEC.decode(window.location.hash.substring(1));
@ -188,7 +194,7 @@ async function streamDecompress() {
},
flush(controller) {
if (decompressStream.result() === BrotliStreamResult.NeedsMoreInput) {
controller.enqueue(decompressStream.decompress(undefined, DECOMPRESS_CHUNK_SIZE));
controller.enqueue(decompressStream.decompress("", DECOMPRESS_CHUNK_SIZE));
}
controller.terminate();