martinellimarco / t2sz

Compress a file into a seekable zstd with special handling for .tar archives
GNU General Public License v3.0
42 stars 0 forks source link

Memory corruption #1

Closed amerlyq closed 3 years ago

amerlyq commented 3 years ago
git clone --depth=1 --single-branch https://github.com/stedolan/jq
tar -cf jq.tar -- jq
t2sz -vfo jq.tar.zst -- jq.tar

+ <null>
# END OF BLOCK (512)

+ <null>
# END OF BLOCK (512)

munmap_chunk(): invalid pointer
[1]    164384 abort (core dumped)  t2sz -vfo jq.tar.zst -- jq.tar

# OR:(sometimes): free(): invalid pointer
──────
(gdb) bt
#0  0x00007ffff7d2eef5 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff7d18862 in abort () from /usr/lib/libc.so.6
#2  0x00007ffff7d70f38 in __libc_message () from /usr/lib/libc.so.6
#3  0x00007ffff7d78bea in malloc_printerr () from /usr/lib/libc.so.6
#4  0x00007ffff7d7901c in munmap_chunk () from /usr/lib/libc.so.6
#5  0x00007ffff7d7dcdb in free () from /usr/lib/libc.so.6
#6  0x00005555555552bc in main (argc=<optimized out>, argv=<optimized out>) at /home/user/.cache/aurutils/airy/t2sz-git/src/t2sz/src/t2sz.c:372
──────
(gdb) f 6
#6  0x00005555555552bc in main (argc=<optimized out>, argv=<optimized out>) at /home/user/.cache/aurutils/airy/t2sz-git/src/t2sz/src/t2sz.c:372
372         free(ctx->outFilename);
──────
(gdb) l
367             }
368         }
369
370         compressFile(ctx);
371
372         free(ctx->outFilename);
373         free(ctx);
374
375         return 0;
376     }
──────
(gdb)
==167002== Invalid free() / delete / delete[] / realloc()
==167002==    at 0x483F9AB: free (vg_replace_malloc.c:538)
==167002==    by 0x1092BB: main (t2sz.c:372)
==167002==  Address 0x1fff000109 is on thread 1's stack
martinellimarco commented 3 years ago

Thank you for reporting this. I will test in a few hours and let you know if I can reproduce the issue.

martinellimarco commented 3 years ago

I can reproduce the bug, I'll investigate and resolve it as soon as possible.

martinellimarco commented 3 years ago

The problem is fixed. There was an unnecessary attempt to free a pointer at the end of the program. All archives produced with previous version are ok. A new release will be published soon. Thanks @amerlyq for reporting this.

martinellimarco commented 3 years ago

v1.0.1 released