DS-Homebrew / GodMode9i

GodMode9i Explorer - A full access file browser for the Nintendo DS and DSi consoles :godmode:
https://wiki.ds-homebrew.com/godmode9i/
GNU General Public License v3.0
499 stars 27 forks source link

Try to add 7z decompress #59

Open beefnoodles opened 4 years ago

beefnoodles commented 4 years ago

I try to add 7z decompress in GodMode9i. Partal function is already complete. but I find that the malloc function always go wrong when alloc big(8MB) memory. The malloc call not return error, but some byte of alloced array is zero. I do some test:

int forbarramtest()
{
    char *buf = (char *)malloc((size_t)8388608);
    for (int i = 0; i < 8388608; i++) {
      buf[i]=1;
    }
    FILE *destinationFile = fopen("sd:/7z/out/ramtest", "wb");
    fseek(destinationFile, 0, SEEK_SET);
    fwrite(buf, 1, 8388608, destinationFile);
    fclose(destinationFile);
    free(buf);
    return 0;
}

In the output file $ xxd ramtest |grep -B4 "00 00"

00397470: 0101 0101 0101 0101 0101 0101 0101 0101  ................
00397480: 0101 0101 0101 0101 0101 0101 0101 0101  ................
00397490: 0101 0101 0101 0101 0101 0101 0101 0101  ................
003974a0: 0101 0101 0101 0101 0101 0101 0101 0101  ................
003974b0: 0101 0101 0101 0101 0000 0000 0000 0000  ................
003974c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
003974d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
003974e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
003974f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00397500: 0000 0000 0000 0000 0000 0000 0000 0000  ................

Some byte in output file is zero, but after those zero data is right. So file bigger than 3MB can not decompress. $ xxd ramtest |tail -10

007fff60: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007fff70: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007fff80: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007fff90: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007fffa0: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007fffb0: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007fffc0: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007fffd0: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007fffe0: 0101 0101 0101 0101 0101 0101 0101 0101  ................
007ffff0: 0101 0101 0101 0101 0101 0101 0101 0101  ................

Test platform: NDSi 1.4.1J TWiLight Menu++: v15.1.1 nds-bootstrap: v0.35.1

0ddb0d commented 3 years ago

Unfortunately I have some bad news.

The default dictionary size used by 7zip is 16MiB and according to the documentation "For decompressing a file compressed by LZMA method with dictionary size N, you need about N bytes of memory (RAM) available."

It sounds like what you are attempting is just not going to work.

RokeJulianLockhart commented 1 year ago

Is that 16MiB uncompressed or compressed with 7z itself?