Page 1 of 1
Arrays of dynarrays can't be indexed correctly
Posted: Tue Jan 08, 2019 10:18 am
by phantombeta
When you try to index a dynarray contained inside an array with a non-constant index, it'll error out with "Invalid resizable array".
Code: Select all
void foo () {
Array<int> a [5];
a.Push (555);
a [3] [0] = 666; // This works fine
int b = random (0, 255);
a [b] [0] = 666; // This errors out
}
Steps to reproduce:
- Try to load the example PK3
I'd really like to see this bug fixed. Right now, the only way to get the array's contents is to copy it to a local variable.
I actually tried to see if I could fix it myself, but couldn't figure anything out. :\
Re: Arrays of dynarrays can't be indexed correctly
Posted: Tue Jan 08, 2019 10:25 am
by Graf Zahl
phantombeta wrote:
I actually tried to see if I could fix it myself, but couldn't figure anything out. :\
Welcome to the club.

This one got me, too.
Re: Arrays of dynarrays can't be indexed correctly
Posted: Tue Jan 08, 2019 10:49 am
by phantombeta
One thing I did figure out is that the constant case works because it pretty much turns constant index array accesses into temporary fields, if that helps at all.
Re: Arrays of dynarrays can't be indexed correctly
Posted: Tue Jan 08, 2019 12:16 pm
by Graf Zahl
I ran into this myself when scriptifying the AutouseHealth function, but I didn't manage to fix it.
Yet Another Array Fix By phantombeta
Posted: Wed Mar 13, 2019 4:28 am
by phantombeta
Fuckssake, the solution was sitting right there in front me the whole time.
Arrays of dynarrays simply needed to be special-cased so that the address of their size value is calculated at runtime instead of compile-time.
PR link.
Re: Arrays of dynarrays can't be indexed correctly
Posted: Wed Mar 13, 2019 5:43 am
by Graf Zahl
That's very much appreciated.
Re: Arrays of dynarrays can't be indexed correctly
Posted: Tue Jun 04, 2019 4:53 pm
by phantombeta
I fixed some bugs in my original fix.
PR link
Due to just blindly copying part of what GZDoom did and freeing the arrayvar register before even using it, the bounds value was getting its value from inside the array's elements. Obvious problem there. It both means it doesn't work correctly, and it also means there's a serious buffer overflow exploit there.
Thankfully, though, there was actually another bug that was making it emit BOUND instead of BOUND_R, which broke it even more - but also stopped the buffer overflow exploit from actually being usable at all.
The PR fixes both bugs.
Re: Arrays of dynarrays can't be indexed correctly
Posted: Wed Jun 05, 2019 12:38 am
by Graf Zahl
Next time, please open a new report for submitting a PR instead of bumping a thread that has been closed.