Skip to content

Prevent array OOB access for traffic-height-map - #4106

Merged
xTVaser merged 1 commit into
open-goal:masterfrom
dallmeyer:b/traffic-height-map-array-oob
Dec 28, 2025
Merged

xTVaser merged 1 commit into
open-goal:masterfrom
dallmeyer:b/traffic-height-map-array-oob

Conversation

@dallmeyer

@dallmeyer dallmeyer commented Dec 28, 2025 •

Copy link
Copy Markdown
Contributor

If the arg0 vector has extreme values, a2-0 and a1-1 can end up being negative, which leads to out-of-bounds access when using these values to read from the xz-height-map's data array, and crashes the game (you can pretty easily reproduce this in jak 3 by overcharging the "superfasthoverbikeglitch")

The min here already makes sure these values don't go too high, but doesn't cover the case when they go negative.

As I understand it, this data in the *traffic-height-map* functions as a 2d array, bucketing x/z coordinates into heights for the vehicle.

@xTVaser xTVaser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems reasonable, code could probably be rewritten to be more readable but something for another day.

there probably is still other out of bounds potential edge cases here (ie. if v1-0 is less than 2 then -1 is going to be the minimum, which is likely out of bounds). But maybe we don't care because those scenarios can't ever happen.

@dallmeyer

Copy link
Copy Markdown
Contributor Author

if v1-0 is less than 2

I don't think that is possible, these are effectively static values since this is only ever used for the *traffic-height-map*

         (v1-0 (-> this x-dim))
         (a3-0 (-> this z-dim))
(deftype xz-height-map (structure)
  (...
   (dim            int16  2)
   (x-dim          int16  :overlay-at (-> dim 0))
   (z-dim          int16  :overlay-at (-> dim 1))
(define *traffic-height-map* (new 'static 'xz-height-map
                               ...
                               :dim (new 'static 'array int16 2 80 #x70)

@xTVaser
xTVaser merged commit a5ac2b0 into open-goal:master Dec 28, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants