Arrays of dynarrays can't be indexed correctly

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Arrays of dynarrays can't be indexed correctly

Re: Arrays of dynarrays can't be indexed correctly

by Graf Zahl » Wed Jun 05, 2019 12:38 am

Next time, please open a new report for submitting a PR instead of bumping a thread that has been closed.

Re: Arrays of dynarrays can't be indexed correctly

by phantombeta » Tue Jun 04, 2019 4:53 pm

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

by Graf Zahl » Wed Mar 13, 2019 5:43 am

That's very much appreciated.

Yet Another Array Fix By phantombeta

by phantombeta » Wed Mar 13, 2019 4:28 am

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

by Graf Zahl » Tue Jan 08, 2019 12:16 pm

I ran into this myself when scriptifying the AutouseHealth function, but I didn't manage to fix it.

Re: Arrays of dynarrays can't be indexed correctly

by phantombeta » Tue Jan 08, 2019 10:49 am

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

by Graf Zahl » Tue Jan 08, 2019 10:25 am

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.

Arrays of dynarrays can't be indexed correctly

by phantombeta » Tue Jan 08, 2019 10:18 am

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. :\
Attachments
NestedDynArrayIndexBug.PK3
(371 Bytes) Downloaded 34 times

Top