maxpl0it Profile picture
Mar 22 8 tweets 2 min read Read on X
@_manfp’s Firefox renderer bug is a beauty that takes advantage of an optimisation implemented just 3 months ago. Let’s break it down!
In JavaScript, you can get a list of property names of an object using Object.keys(o). A common pattern to count the number of properties an object has is to use Object.keys(o).length.
Now, this can actually end up being quite slow for large objects, since Object.keys(o) constructs a whole new array with the property names in it. Image
If we’re just interested in the length of this array and not the array itself, this means we’re spending considerable time constructing arrays when we don’t need to.
Thankfully, 3 months ago, Mozilla added a nice optimisation that means the pattern of Object.keys(o).length no longer creates this array, saving us from wasting a LOT of memory.
github.com/mozilla/gecko-…
Image
So where’s the bug? In the Range Analysis part of the just-in-time compiler! The range that was given to the new MObjectKeysLength JIT node was between 0 and NativeObject::MAX_SLOTS_COUNT, which is (1 << 28) - 1.
However, the number of properties we can add is much larger.
Here is a test case that shows this behaviour. The returned value should never be larger than (1 << 28) - 1, which is 268435455. The trigger shows that we can in fact go larger than this, a value that is not taken into account by the range analysis.
Image
Image
This can lead to an incorrect elimination of a bounds check for an array access and therefore an out-of-bounds read and write primitive.
Definitely one of the neatest Firefox bugs I’ve seen in a while!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with maxpl0it

maxpl0it Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(