Don't allow writes to inner objects through immutable properties
commitb5c7f27cbbbbf4a5af9f7c0770425d42e953734b
authorAlexey Toptygin <alexeyt@fb.com>
Sun, 15 Apr 2018 09:31:06 +0000 (15 02:31 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Sun, 15 Apr 2018 09:35:09 +0000 (15 02:35 -0700)
treebbc367f2085943287cded8b149f1c26e9d3853ee
parentfe5f3b86c89217af5efcdba9fa7124c26ffeed89
Don't allow writes to inner objects through immutable properties

Summary:
If you have a mutable object embedded in an immutable property of another object, you can grab the inner, mutable object into a local and write to it. This changes the 'var_dump' view of the immutable property, but it is legal because immutability is shallow.
I initially thought that it would be useful to support writing to the inner, mutable object's properties using multi-level dims that pass through an immutable property. However, I only got it working if the mutable object was directly embedded in the immutable one, not if there was an array that had to be dimmed through in between (because that would have required keeping track of state that we didn't/don't track).
We had a design meeting to discuss if we wanted this behavior at all, and decided it was confusing, and we should never allow any writes that dim through an immutable property, even if you can accomplish the same thing by grabbing the inner, mutable object into a local and doing the same write via the local.
Remove the special case for dimming from an object into another object, and add a unit test.

Reviewed By: paulbiss

Differential Revision: D7581144

fbshipit-source-id: b047f014cbf89e03d18ada2077f2e5955bd48a4f
hphp/runtime/base/object-data.cpp
hphp/test/slow/object/immutable/dim-for-write.php [new file with mode: 0644]
hphp/test/slow/object/immutable/dim-for-write.php.expect [new file with mode: 0644]