Skip to content

fix: prevent infinite loop in multiline string preprocessing#16

Open
novusr wants to merge 1 commit intoopenmultiplayer:masterfrom
novusr:master
Open

fix: prevent infinite loop in multiline string preprocessing#16
novusr wants to merge 1 commit intoopenmultiplayer:masterfrom
novusr:master

Conversation

@novusr
Copy link

@novusr novusr commented Feb 25, 2026

Summary

Fixed a critical bug where the compiler could enter an infinite loop during multiline string preprocessing if file reading unexpectedly stopped or reached EOF.

Description

In source/compiler/sc2.c, the functions unpackedstring and packedstring handle multiline strings by calling preprocess() to fetch subsequent lines. Previously, there was no check to see if preprocess() actually succeeded in reading more data. If the file ended abruptly (EOF) or reading failed, the loop would continue indefinitely because the termination condition was never met.

Example of Bug (Reproduction)

To see this issue in action, create a file named test_bug.pwn containing an unclosed multiline string right at the end of the file:

native print(const string[]);

main() {
    print("this string is never closed);
}

Before the patch:
If you compile this file using the older compiler version, it gets stuck in an infinite loop and hangs indefinitely parsing the string, taking 100% CPU on a single core until forcibly killed.

$ pawncc test_bug.pwn
Pawn compiler 3.10.11                   Copyright (c) 1997-2006, ITB CompuPhase
(hangs forever...)

After the patch:
With the fix, the compiler successfully detects the end of the file, breaks out of the string parse loop, and displays the correct invalid string errors:

$ pawncc test_bug.pwn
Pawn compiler 3.10.11                   Copyright (c) 1997-2006, ITB CompuPhase

test_bug.pwn(4 -- 5) : error 037: invalid string (possibly non-terminated string)

1 Error.

This patch adds a check for the freading flag immediately after calling preprocess(). If freading is false, it resets the imlstring state and breaks out of the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant