Skip to content

v2.0.0

Choose a tag to compare

@Snesnopic Snesnopic released this 12 Nov 10:05
· 46 commits to main since this release

What's new

BIG release about speed and safety. A single large file can now use every thread. On a mixed corpus with 10 threads, a run takes 42.9 s instead of 97.7 s. Every rebuilt container is now read back and compared with its source before it replaces the original, and zip-based files are rewritten by chisel itself, with their headers kept as they were. This release also fixes some files that could come out damaged. JPEGs get about 1% smaller from a much deeper search of their progressive scans.

Behavior changes

  • PDFs are linearized only if they already were. 1.12.0 linearized ("fast web view") every PDF, adding hint tables to files that didn't have them. PDFs come out 0.2% to 6.7% smaller in our tests.

  • A rebuilt container replaces the original only if it reads back as its source and is smaller than the original. Otherwise the original is kept and an [ERROR] is logged:

    • PDFs: the rebuilt object graph is compared with the original, stream by stream;
    • archives: entries, names, metadata and contents are compared;
    • zip-based files: headers are compared field by field and every entry is checked;
    • every other container (audio and video with covers, ICO, ICNS, MIME, HTML/CSS...) is extracted again and its contents compared with what went in;
    • Matroska: every track is compared frame by frame, see the bug fixes below.
  • Files that are both recompressed and containers (FLAC, WavPack, Ogg, MKV, MP4, PSD... with cover art or attachments) no longer replace the original halfway through: the recompressed file waits until its covers are back in, and only the finished file replaces the original.

  • Zip-based files are rewritten by chisel, no longer by libarchive: zip, cbz, jar, xpi, apk, epub, ora, xps, dwfx, the Office Open XML formats (docx, xlsx, pptx...) and OpenDocument.

    • Local and central headers, raw names, DOS dates, extra fields, attributes, comments, __MACOSX entries and the order of the entries stay as they were. Only the data, CRCs, sizes and offsets change.
    • The one exception is Office's 0xA220 extra field, which only holds zero padding and is removed.
    • Entries chisel can't safely rewrite (folders, symlinks, encrypted, bzip2 or LZMA entries) are copied. Zips it can't read safely like split archives still go through libarchive.
  • TIFFs are rewritten by chisel:

    • Image data stored without loss (uncompressed, LZW, PackBits, Deflate) is recompressed with zopfli, with the horizontal predictor only where it makes the data smaller. Colors are no longer converted.
    • Tiled images are recompressed only if they already used Deflate: macOS can't read Deflate tiles. JPEG images, and files with a MakerNote, DNG private data or free-space offsets, are left as they are.
    • Every rewritten file is always read back and compared with the original, tags and decoded image data. A file that doesn't match is left as it is and logged as [ERROR].
    • With --no-meta, Make, Model, Software, DateTime, Artist, HostComputer, Copyright, XMP, IPTC, EXIF and GPS are removed. Resolution and the ICC profile now stay.
  • Matroska: mkclean no longer switches tracks to zlib compression, which many players can't decode anyway (see the bug fixes below). Tracks already compressed with zlib, bzlib or LZO are left as they are.

Improvements

  • Faster on all threads:

    threads 1 2 4 6 8 10
    1.12.0 284.9 s 164.1 s 101.3 s 101.7 s 95.0 s 97.7 s
    2.0.0 258.2 s 134.9 s 72.0 s 55.8 s 48.8 s 42.9 s

    (Mixed corpus). CPU time at 1 thread is 20% lower, and the output is the same whatever the number of threads.

    • PDF: streams and object streams are compressed in parallel, where 1.12.0 rebuilt each PDF on one thread. A comic book PDF went from 8.7 s to 2.4 s with 5 threads.
    • zopfli (PDF streams, zip entries...): large inputs are optimized in parallel blocks, and it takes 40% less CPU.
    • zopflipng: its filter strategies run in parallel, 2.2× faster.
    • FLAC: decoding and encoding run on the pool. A 24-bit/192 kHz track went from 13.3 s to 11.2 s with 10 threads.
    • GIF: the slowest GIF of our corpus went from 42.8 s to 10.7 s, and the whole corpus from 47.3 s to 21.1 s, with 10 threads.
    • JPEG XL: a 4096×4096 image went from 57 s to 9 s.
    • Containers are rebuilt as soon as their contents are processed, while other files are still being recompressed.
  • Zip-based files get smaller: entries that compress well are deflated with zopfli, on the thread pool. An Excel workbook went from 9,387 to 8,635 bytes (−8%), test documents (odt, epub, docx) shrank by 10–11%, and zips of source code that 1.12.0 couldn't shrink lost 1–2%. JPEG entries, as in comic books, are left to zlib: zopfli would gain 0.3% at about 1.5 s per MB.

  • JPEG: besides mozjpeg's progressive and baseline encodings, chisel tries the progressive scan script found by jpegultrascancpp, and keeps the smallest. On a random sample of 585 JPEGs it took another 1% off what chisel already saved (9.5%); 527 of them got smaller, by up to 11.7%.

  • TIFF: 16- and 32-bit, floating-point and CMYK images, which were previously skipped, are now recompressed too.

  • Ctrl-C stops a run much faster (1-4 seconds instead of more than 100).

  • New --trace FILE option: writes a timeline of every task (Chrome trace JSON, for Perfetto).

Bug fixes

Data loss

  • Matroska (MKV, MKA, WebM): tracks with PCM audio, uncompressed video or bitmap subtitles (Blu-ray PGS, DVD VobSub, USF, VobBtn) were destroyed. mkclean switched them to zlib compression, which mkclean couldn't write correctly: an MKA with 2.1 MB of PCM audio came out at 1,186 bytes, with no audio left. Video and audio in other codecs, text subtitles and WebM files were not affected.

    • chisel now reads every track of the original and of the result with its own Matroska reader, and compares them frame by frame: codec, codec private data, every frame (with header removal and zlib undone, whatever the lacing), block additions such as alpha channels, and discard padding. In the result, the SeekHead and the cues must point at the right clusters and blocks.
    • This runs after mkclean and again after attachments are put back, always, not only with --verify-checksums. A file that doesn't match is left as it is and logged as [ERROR]. It costs about 0.2 s per GB.
  • Damaged Matroska files: mkclean drops what it can't read, and chisel accepted the shorter file: a damaged 64 KB MKV came out at 542 bytes. Files with data chisel can't read, or with data after their segment (e.g. a second segment), are now left as they are.

  • SQLite databases in use: a database with a -wal file next to it (an app still had it open, or didn't close it cleanly) came out corrupted. The rewritten database already held the changes from the -wal, but the old -wal stayed next to it and was applied again when the database was opened: the integrity check failed and rows were wrong. Databases with a -wal, -shm or -journal file next to them are now left as they are.

  • gzip: anything after the last member (padding, appended data) was dropped. It's now kept.

  • miniSEED: the samples stayed the same, but rebuilt records lost what their headers said about them:

    • miniSEED 3 files were rewritten as miniSEED 2, which rounds nanosecond start times to the microsecond;
    • flags such as "clock locked" and the timing quality were reset;
    • record start times were recomputed from the first sample, moving them by 1–2 µs where the recorder's clock had drifted.

    Now the miniSEED version, every header field, flag and extra header, and every record's start time are kept. Each rebuilt block of records is read back and checked, and blocks that can't be rebuilt without loss (e.g. records with a timing exception) are copied as they are.

  • MP3: in rare files the recompressed audio decoded differently from the original: MPEG-2 and 2.5 files using preflag or intensity stereo (LAME never writes them), audio resuming after a damaged frame or a tag in the middle of the stream, and frames that decoders don't all read the same way, which are now copied byte for byte.

  • Interrupted runs: stopping chisel (Ctrl-C) while the covers of a FLAC, Ogg, WavPack or MKV file were being optimized left the intermediate file in place of the original, with re-encoded audio and the old covers. The original now stays.

Files other programs couldn't read

  • TIFFs with EXIF data came out with a broken EXIF directory, and macOS Preview and ImageMagick couldn't open them. Even with metadata kept, orientation, artist, copyright, camera make and model, GPS and IPTC data were lost. See the behavior changes above.
  • BGZF and dictzip files (.vcf.gz, .bam, .dz...): their blocks were recompressed but the block sizes in their headers weren't updated, so htslib (samtools, bcftools...) couldn't read them, and their indexes (.tbi, .csi, .bai) pointed to the wrong places. gzip files with an extra field are now left as they are.
  • PDF/A files failed validation once rebuilt: PDF/A-1 files got object streams, which PDF/A-1 doesn't allow, and the end of line PDF/A requires before endstream was dropped. With --no-meta, the XMP metadata that declares a file PDF/A was removed too. chisel now reads the PDF/A part from the XMP and keeps the file conformant: no object streams in PDF/A-1, an end of line before every endstream, XMP streams left uncompressed, and the declaring XMP kept even with --no-meta. Rebuilt PDF/A-1b and PDF/A-2b files pass veraPDF.

Metadata changed

  • Zip-based files, rebuilt by libarchive, changed in several ways; they're now kept as they were (see the behavior changes above):

    • zips made on Windows had their DOS times rewritten in the local time zone, their permissions set to 664 and their NT security descriptors dropped;
    • on macOS, __MACOSX/ entries were folded into the files' metadata, so rebuilt zips lost them;
    • non-ASCII names were Unicode-normalized, a timestamp extra field and data descriptors were added, DOS times were rounded down to even seconds, and DOS attributes, comments and the UTF-8 flag on ASCII names were dropped.
  • MP3 headers: the LAME tag kept the original's music length, the VBRI header written by Fraunhofer encoders kept its old frame and byte counts, and CBR files that came out VBR were still tagged as CBR (Info instead of Xing), which players read to compute duration and to seek. They're now updated to match the file.

Errors and crashes

  • MP3 files with data before the first frame failed with [ERROR] Pipeline failed and were left as they were. They're now recompressed, with that data kept.
  • Terminal width: in a terminal that reports a width of 0 columns (e.g. a pseudo-terminal that never got a size), every progress-line update printed about 4 GB of spaces. Redirected to a file, one run wrote 38.8 GB. chisel now assumes 80 columns.
  • Archives: chsl crashed on some damaged archives, when libarchive failed without giving a reason.
  • Matroska, fixed in our libmkclean fork:
    • a block of 256 frames with fixed-size lacing, which is valid, sent mkclean into an endless loop in builds compiled with GCC (the Linux ones), so chsl never finished;
    • damaged files could crash chsl, or make mkclean read and write past its buffers: unreadable blocks still referenced by a cue, emptied clusters used after being freed, elements with a broken size taken for another type, sizes close to the 64-bit limit, laces whose sizes don't add up, mandatory strings without a value. 7,800 damaged test files now give no crash and no hang;
    • processing several MKVs at once could start some of them with mkclean's format tables half set up;
    • mkclean leaked memory for every cluster of files whose clusters have no declared size, like those recorded by browsers, and in a few other places on damaged files;
    • an EBML function returning nothing where a result was expected could crash mkclean in some builds.
  • Console: log lines and the progress bar were written under two different locks, so they could garble each other.
  • mkclean messages (e.g. about a damaged cluster) were printed straight to the console, even with --quiet and without the file name. They now go to the log as debug messages that name the file, and when mkclean fails, the warning includes its last message.

Other

  • WavPack files with cover art could grow: their recompressed audio was larger than the original, but the file looked smaller until the cover was put back. They're now left as they are.
  • M4A files were rewritten even when the space saved on their covers was kept as padding by TagLib, so they came out the same size. They're now left untouched.

Dependencies

  • Updated libmkclean fork: no zlib track compression, files with compressed tracks refused, the crash, hang and leak fixes above, and its messages handed to chisel instead of printed.
  • Updated zopfli fork: parallel block optimization through a hook, and faster tree computations.
  • Updated qpdf fork: hooks to compress object streams in parallel and to reuse them when linearizing.
  • Updated flacoutcpp and optigif: their parallel work runs through a hook, on chisel's thread pool. flacoutcpp now keeps ID3v2 tags in front of the stream itself, and its stereo-mode search and all-zero partitions shave a few more bytes off each FLAC.
  • Updated mp3packercpp: the MP3 fixes above.
  • Added jpegultrascancpp (Apache-2.0): JPEG scan search, on chisel's thread pool.
  • Updated mseedout to 1.2.0 and later fixes: a new packer, a native miniSEED 3 writer, headers and times kept, every rebuilt block verified. libmseed 3.5.4.
  • Updated libarchive 3.8.9 → 3.8.11, SQLite 3.53.4 → 3.54.1, libpng (fixes on the 1.6 branch), libtiff 4.7.2 → master (overflow and hardening fixes), TagLib 2.3.2 → master (bounds checks, FLAC picture and RIFF size overflows) and WavPack 5.9.0 → master (undefined behavior and a use-after-free when decoding damaged files).

Development

  • macOS builds use the SDK of the selected Xcode, and the Rust bridge links without Corrosion's Command Line Tools path.

macOS: removing the Gatekeeper quarantine

When downloading binaries from the internet, macOS automatically marks them as “quarantined”.
If you try to run chsl and macOS shows a warning like:

“chsl cannot be opened because it is from an unidentified developer”

…you need to remove the quarantine attribute manually.

How to remove the quarantine flag
Open Terminal in the folder where you downloaded chsl and run:

xattr -d com.apple.quarantine ./chsl

To verify that the quarantine flag is gone:

xattr ./chsl

If com.apple.quarantine no longer appears, you're good to go.
Now you can run:

./chsl ...

Note
This issue does not occur if you compile chsl yourself.