Reapply "validate path lengths before writes and attempt to eagerly c… (#69569)
Reland of #69141 after it got reverted. Turns out there was a GT submit
that got lost (along with the associated commit) somehow.
---------
Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>