Skip to content

v0.4.1: fix a crash on Linux with glibc

Choose a tag to compare

@kenshaw kenshaw released this 15 Nov 01:38
· 38 commits to main since this release

This release fixes a crash on Linux. Upgrade if you build on Linux with gcc, which is the default.

Fixed: a crash on Linux with glibc

Every release up to v0.4.0 can crash with a segmentation fault on Linux when the program links glibc, which is what gcc does on most Linux systems. A script of 17 bytes that starts with #! /usr/bin/cmd1 is enough. Other files get wrong descriptions, such as the size of a Netpbm image.

The Linux archives were compiled against the headers of musl, where regmatch_t has 8-byte offsets, and glibc writes 4-byte ones. libmagic then read the positions of a regular expression match wrongly.

The Linux archives now carry their own regex engine, libgnurx, which the Windows archives already use, under renamed names. libmagic never calls the regex functions of the C library, so the output is the same with glibc and with musl.

The new harness of the pure Go port found the crash. It builds libmagic 5.48 from the source of file as an oracle, and compares the package with it on 1,544 inputs and 11,571 questions. They now agree when the program links glibc, and when it links musl.

Versions

  • Root v0.4.1. The API does not change.
  • Target modules: v5.48.2 for linux_amd64, linux_arm64 and linux_arm, which hold the new archives. The others do not change.
  • libmagic 5.48, zlib 1.4, bzip2 1.0.8, xz 5.8.4, zstd 1.5.7.
  • libgnurx 2.5.1 is now in the Linux archives as well as the Windows ones. It is under LGPL 2.1.

Known limits

  • A program for linux/arm (32-bit) cannot link the archives with glibc, because they call the names that musl gives to its 64-bit time functions. Every release has this. linux/arm64 needs glibc 2.38 or later for strlcpy.
  • macOS has no CI, so the darwin archives are compiled and not run.