[layout box merge] Layout boxes as private bases of renderers (refactor)
Component: WebCore layout | cd25d8a
Source/WebCore/layout/integration/LayoutIntegrationBoxTreeUpdater.cpp
Source/WebCore/layout/integration/LayoutIntegrationBoxTreeUpdater.cpp
WebKit에 LFC(Layout Formatting Context)가 통합된 이후, inline과 grid formatting context는 별도의 Layout::Box tree 위에서 동작해 왔습니다. 이 tree는 BoxTreeUpdater가 render tree를 바탕으로 구성했습니다. 이 과정에서 style과 text를 복사하고 두 tree를 계속 동기화했으며, line layout은 box tree 내부를 가리키는 reference를 보유했습니다.
이번 commit에서는 Layout::ElementBox와 Layout::InlineTextBox가 각각 RenderElement와 RenderText의 private base로 변경되었습니다. 결과적으로 모든 renderer가 그 자체로 layout box가 되었습니다. box navigation은 render tree의 link를 직접 읽도록 바뀌었고, RenderObject::layoutBox()는 더 이상 null이 되지 않습니다. 기존의 null check는 formatting context root box에 설정되는 isInLiveFormattingContext() / isLaidOutByIntegration() flag로 대체되었습니다.
Significance
Release arm64 기준으로 element renderer와 box를 합친 크기는 304바이트에서 176바이트로, text renderer와 box는 256바이트에서 208바이트로 줄었으며, 병렬 tree 하나와 그 동기화 로직이 통째로 제거되었습니다. 다만 inline이나 grid context 밖에 있는 element renderer는 오히려 24바이트 커집니다. 보안 관점에서 의미 있는 변화는 따로 있습니다. 이제 box를 가리키는 stale reference는 곧 renderer를 가리키는 stale reference에 해당합니다.
Audit directions
Narrow: renderer에서 box로의 변환은 private base를 거치며, 여기에는 memory-unsafe-cast suppression이 적용되어 있습니다. 게다가 fromLayoutBox()는 두 분기 모두에서 동일한 offset을 계산합니다. 즉 변환의 정확성은 호출 측이 지키는 type invariant에 전적으로 의존합니다. 그래서 Box를 RenderElement/RenderText로 변환하는 모든 호출 지점을 점검할 필요가 있습니다. 특히 initial containing block은 renderer가 아닌 유일한 독립 ElementBox이므로 주의 깊게 살펴봐야 합니다. 한편 renderer와 box는 이제 별도의 CheckedPtr counter를 가지며, 삭제 시점에 둘 다 검사됩니다. renderer가 파괴된 뒤에도 Layout::Box reference를 계속 붙잡고 있는 holder가 있는지 확인해야 합니다.
Wider: commit 설명에 따르면, 일부 제거 경로는 이제 해당 box를 참조하는 line layout을 함께 파괴합니다(invalidateLineLayout, destroyLineLayoutReferringTo, detachFromRenderElement, dropAnonymousBoxChild). 나머지 제거 및 re-parenting 경로에도 같은 공백이 남아 있는지 점검할 필요가 있습니다. 대상으로는 first-letter, list marker, slot 재할당, inline context 안의 iframe/replaced content, RenderButton 내부 renderer, RenderListBox/RenderMenuList 등이 있습니다.
LineLayout/GridLayout의 constructor와 destructor에서 live-context flag 갱신이 누락되면, 이미 죽은 content가 live 상태로 보일 가능성이 있습니다. 또한 style이 이제 box에 저장되므로, willBeDestroyed 이후에 발생하는 read도 확인해야 합니다. 포함된 test는 crash가 나지 않는지만 검사합니다. 따라서 DOM 제거, display:none, slot 변경, 혼합된 replaced content를 대상으로 fuzzing을 수행하는 것이 필요합니다. 이때 renderer 즉시 파괴 옵션을 켠 경우와 끈 경우를 모두 다뤄야 합니다.