Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New compiler: potential code buffer overflow when compiling certain snippets #2418

Open
ivan-mogilko opened this issue May 8, 2024 · 0 comments
Labels
ags 4 related to the ags4 development context: script compiler type: bug unexpected/erroneous behavior in the existing functionality

Comments

@ivan-mogilko
Copy link
Contributor

CC @fernewelten

As demonstrated by #2417.

Certain code snippets cause write or read beyond the valid data in code buffer.
This was never noticed before, because compiler allocates this buffer with an extra capacity, and offset mistakes are quite small (few bytes).

Errors occur in functions AGS::ForwardJump::Patch and AGS::BackwardJumpDest::Set.

Specifically, following tests cause the error:

Bytecode1.Ternary5

        float main()
        { 
            int I1a = 0 ? 10 : 20;
            int I1b = 2 ? 30 : 40;
            int I2a = 0 ?: 50;
            int I2b = 3 ?: 60;
            int I3a = 0 ? I1a : (7 + I1b);
            int I3b = 4 ? I2a : (7 + I2b);
            int I4a = 0 ? 70 : I3a;
            int I4b = 4 ? 80 : I3b;
            int I5a = 0 ? I4a : 90;
            int I5b = 5 ? I4b : 100;
            int I6 = 0 ? : I5a;
            return 0.;
        }

Compile0.Ternary02

        int main()
        {
            return 2 < 1 ? 1 : 2.0;
                    break;
        } 

Compile1.CompileTimeConstant2

        int main() {
            while (1)
            {
                const int CI2 = 4712;
            }
            float CI2;
        }
@ivan-mogilko ivan-mogilko added type: bug unexpected/erroneous behavior in the existing functionality ags 4 related to the ags4 development context: script compiler labels May 8, 2024
@ivan-mogilko ivan-mogilko added this to the 4.0.0 (preliminary) milestone May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ags 4 related to the ags4 development context: script compiler type: bug unexpected/erroneous behavior in the existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant