[File] file-5.46 segfault on Cygwin (only)
raf
file at raf.org
Sun Jun 7 09:50:13 EDT 2026
On Sat, Jun 06, 2026 at 01:56:33PM +0200, Christoph Biedl <astron.com.bwoj at manchmal.in-ulm.de> wrote:
> raf wrote...
>
> > Strangely, 5.46 on macOS and Debian don't crash with this file.
> > It's just the 5.46 on Cygwin.
> >
> > I compiled 5.46 on Cygwin myself to see if it's something
> > wrong just with the Cygwin package of file-devel but that
> > crashed too.
> >
> > 5.47 on all three systems doesn't crash, so that's good.
>
> Out of curiosity, were you able to bisect to identify the commit that
> fixed the issue?
>
> Christoph
Hi Christoph,
No, I just used 5.46 and 5.47 from the ftp site.
While bisecting, I came across this commit which looked promising:
[1550a570cbe35c5d2520fe812e4871c596c74f14] PR/578: Don't crash on cygwin when tm_mon == -1
But that didn't compile because of:
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -DMAGIC=\"/usr/local/share/misc/magic\" -fvisibility=hidden -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wsign-compare -Wreturn-type -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wextra -Wunused-parameter -Wformat=2 -g -O2 -MT print.lo -MD -MP -MF .deps/print.Tpo -c print.c -DDLL_EXPORT -DPIC -o .libs/print.o
print.c: In function 'file_fmtdate':
print.c:357:32: error: invalid type argument of '->' (have 'struct tm')
357 | if (tm.tm_mon < 0 && tm->tm_mon > 11)
| ^~
The first testable commit that's fixed is:
ef18b1218393210ae7a7f83c82d69f82c62a3941 is the first new commit
commit ef18b1218393210ae7a7f83c82d69f82c62a3941
Author: Christos Zoulas <christos at zoulas.com>
Date: Mon Dec 9 06:22:27 2024
fix wrong logic.
So presumably it was 1550a570 that started the fix:
@@ -352,6 +352,10 @@ file_fmtdate(char *buf, size_t bsize, uint16_t v)
memset(&tm, 0, sizeof(tm));
tm.tm_mday = v & 0x1f;
tm.tm_mon = ((v >> 5) & 0xf) - 1;
+ // Sanity check because some OS's coredump with invalid values.
+ // Yes, Cygwin I am looking at you!
+ if (tm.tm_mon < 0 && tm->tm_mon > 11)
+ tm.tm_mon = 0;
tm.tm_year = (v >> 9) + 80;
if (strftime(buf, bsize, "%a, %b %d %Y", &tm) == 0)
That had a typo that stopped subsequent commits from compiling.
The -> error was fixed later, and ef18b1218 fixed the && error:
- if (tm.tm_mon < 0 && tm.tm_mon > 11)
+ if (tm.tm_mon < 0 || tm.tm_mon > 11)
cheers,
raf
More information about the File
mailing list