zen-fs / zip

ZenFS Backend for zip files
https://zenfs.dev/zip/
MIT License
5 stars 3 forks source link

Incorrect array slice #4

Closed atty303 closed 5 months ago

atty303 commented 5 months ago
    const rootZip = await fetch(`https://pob-web-asset.atty303.ninja/versions/v2.42.0/root.zip`);
    await zenfs.configure({
      mounts: {
        "/root": {
          backend: Zip,
          data: await rootZip.arrayBuffer(),
          name: "root.zip",
        },
      },
    });

    console.log(await zenfs.promises.exists("/root/.image.tsv"));

This causes the following error.

RangeError: Offset is outside the bounds of the DataView
    at DataView.prototype.getUint32 (<anonymous>)
    at deserialize (utilium.js?v=defcc128:413:29)
    at new FileEntry (zip.js:212:9)
    at new ZipFS (ZipFS.js:84:24)
    at Object.create (ZipFS.js:175:16)
    at resolveMountConfig (chunk-N5MENFCO.js?v=defcc128:13743:32)
    at async Module.configure (chunk-N5MENFCO.js?v=defcc128:13767:28)
    at async DriverWorker.start (worker.ts?worker_file&type=module:79:9)

This exception itself stopped appearing after a simple (but wrong) change.

-           const cd = new FileEntry(this.data, this.data.slice(ptr, sizeof_FileEntry));
+           const cd = new FileEntry(this.data, this.data.slice(ptr));

Another exception will be made.

 Error: No such file or directory
    at _ErrnoError.With (http:/root/rootlocalhost:5173/rootnode_modules/root.vite/rootdeps/rootchunk-H4GO7QOY.js?v=defcc128:163:12)
    at ZipFS.statSync (http:/root/rootlocalhost:5173/root@fs/rootC:/rootUsers/rootatty/rootsrc/rootgithub.com/rootatty303/rootzenfs-zip/rootdist/rootZipFS.js:111:30)
    at ZipFS.stat (http:/root/rootlocalhost:5173/rootnode_modules/root.vite/rootdeps/root@zenfs_core_filesystem__js.js?v=defcc128:473:19)
    at realpath (http:/root/rootlocalhost:5173/rootnode_modules/root.vite/rootdeps/rootchunk-N5MENFCO.js?v=defcc128:13349:28)
    at realpath (http:/root/rootlocalhost:5173/rootnode_modules/root.vite/rootdeps/rootchunk-N5MENFCO.js?v=defcc128:13346:47)
    at Object.exists (http:/root/rootlocalhost:5173/rootnode_modules/root.vite/rootdeps/rootchunk-N5MENFCO.js?v=defcc128:13098:55)
    at DriverWorker.start (http:/root/rootlocalhost:5173/root@fs/rootC:/rootUsers/rootatty/rootsrc/rootgithub.com/rootatty303/rootpob-web/rootpackages/rootdriver/rootsrc/rootjs/rootworker.ts?worker_file&type=module:88:42)

The same exception occurs with zenfs.promises.exists("/root"), so it seems to be caused by the absence of "/" in the ZipFS entries.

james-pre commented 5 months ago

I'm sorry—v0.4.1 should fix this. Perhaps some tests are needed.

james-pre commented 5 months ago

@atty303 Does v0.4.1 fix this?

atty303 commented 5 months ago

One of the two problems has been solved. I have created a new Issue for the one that has not yet been fixed.

james-pre commented 5 months ago

@atty303,

-           const cd = new FileEntry(this.data, this.data.slice(ptr));
+           const cd = new FileEntry(this.data, this.data.slice(ptr, sizeof_FileEntry));

In v0.4.0, I made this change to slice the entry at the correct size since the previous behavior would slice from ptr until the end of the file.

This, for some reason, causes an error to be thrown here.

I'm investigating this issue more.

james-pre commented 5 months ago

@atty303 I've found the root cause of the issue, and corrected it: utilium 6cf8815

james-pre commented 5 months ago

This has been updated and is now tested.