gprolog icon indicating copy to clipboard operation
gprolog copied to clipboard

format segfaults when given a format control sequence of '~s' and a number of character codes over a certain size

Open adamcrussell opened this issue 11 months ago • 6 comments

I ran into this while trying to output 64820 character codes. I then ran a few experiments to see when it would fail. I arrived at a failure point of 10265.

| ?- length(As, 10264), maplist(=(65), As), format('~s', [As]).

At this point 10264 As are printed without problem.

| ?- length(As, 10265), maplist(=(65), As), format('~s', [As]).

Here many As printed, not sure of it's 10264 or less, then followed by

Fatal Error: Segmentation Violation (bad address: 0x0)

% uname -a
Darwin arussell-armMBP-YX03 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:54 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6030 arm64
% gprolog --version
Prolog top-Level (GNU Prolog) 1.5.0
Copyright (C) 1999-2024 Daniel Diaz

adamcrussell avatar Jan 16 '25 18:01 adamcrussell

Both queries succeed for me without errors or crashes using the latest git version on macOS Intel 14.7.2.

pmoura avatar Jan 16 '25 18:01 pmoura

I just tried

length(As, 10265), maplist(=(65), As), format('~s', [As]).

on two other machines, both Arm based Macs running MacOS, with 1.5.0. In both cases I get the same segfault behavior.

Will try a very different system (Intel Windows) later today when I get a chance.

adamcrussell avatar Jan 16 '25 21:01 adamcrussell

I can reproduce the crash on OSX 10.14.2:

...
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Fatal Error: Segmentation Violation (bad address: 0x0)

triska avatar Jan 16 '25 21:01 triska

Will try a very different system (Intel Windows) later today when I get a chance.

The Windows test wasn't very informative. The gprolog window would crash but before I could see any output. Possibly it segfaulted, but also possibly it was just a limitation of the gprolog window in displaying this amount of text.

adamcrussell avatar Jan 17 '25 02:01 adamcrussell

You can run GNU Prolog on Windows from the command line (e.g. using PowerShell).

pmoura avatar Jan 17 '25 14:01 pmoura

Will try a very different system (Intel Windows) later today when I get a chance.

The Windows test wasn't very informative. The gprolog window would crash but before I could see any output. Possibly it segfaulted, but also possibly it was just a limitation of the gprolog window in displaying this amount of text.

I just ran Prolog 1.5.0 on a Windows 10 system. This bug did not appear there. This was a different system than the first Windows computer I tried. In this case the gprolog window did not even crash.

So far this only seems to segfault on Apple Arm systems.

adamcrussell avatar Jan 18 '25 03:01 adamcrussell