Integer overflow in Layout (CVE-2024-7025)
An integer overflow in Chromium's layout engine occurs when applying justification to ruby text, causing a security DCHECK failure. An attacker could trigger a browser crash by loading a crafted HTML page.
Tashita Software Security Follow
Originally disclosed on Chrome VRP
- Fix shipped in 14 days
Security Bug
Important: Please do not change the component of this bug manually.
Please READ THIS FAQ before filing a bug: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/faq.md
Please see the following link for instructions on filing security bugs: https://www.chromium.org/Home/chromium-security/reporting-security-bugs
Reports may be eligible for reward payments under the Chrome VRP: https://g.co/chrome/vrp
NOTE: Security bugs are normally made public once a fix has been widely deployed.
VULNERABILITY DETAILS
string_view.h Security DCHECK failed: length <= impl.length() - offset
Initial Considerations
The Security DCHECK was recently introduced on Chrome 129.0.6668.42, but the root cause is an Integer Overflow introduced on Chrome 127.0.6533.57 (see Bisect part).
Stack Trace
FATAL:string_view.h(351)] Security DCHECK failed: length <= impl.length() - offset.
#0 0x000055d154e663cc in ImmediateCrash () at ../../base/immediate_crash.h:176
#1 HandleFatal() () at ../../base/logging.cc:1073
#2 0x000055d154e6571e in operator() () at ../../base/logging.cc:773
#3 InvokeCallback () at ../../third_party/abseil-cpp/absl/cleanup/internal/cleanup.h:87
#4 ~Cleanup () at ../../third_party/abseil-cpp/absl/cleanup/cleanup.h:106
#5 Flush() () at ../../base/logging.cc:956
#6 0x000055d154e667d9 in ~LogMessageFatal() () at ../../base/logging.cc:1078
#7 0x000055d162f47b23 in Set () at ../../third_party/blink/renderer/platform/wtf/text/string_view.h:349
#8 StringView () at ../../third_party/blink/renderer/platform/wtf/text/string_view.h:326
#9 StringView () at ../../third_party/blink/renderer/platform/wtf/text/wtf_string.h:734
#10 BuildJustificationText() () at ../../third_party/blink/renderer/core/layout/inline/justification_utils.cc:78
#11 0x000055d162f45bce in ApplyJustificationInternal() () at ../../third_party/blink/renderer/core/layout/inline/justification_utils.cc:299
#12 0x000055d162fd966f in ApplyRubyAlign() () at ../../third_party/blink/renderer/core/layout/inline/ruby_utils.cc:455
#13 0x000055d162fafeed in PlaceRubyAnnotation() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:514
#14 0x000055d162fada02 in PlaceRubyColumn() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:500
#15 0x000055d162fa8d8c in HandleItemResults() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:175
#16 0x000055d162fa809d in CreateLine() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:72
#17 0x000055d162c8eacb in CreateLine() () at ../../third_party/blink/renderer/core/layout/inline/inline_layout_algorithm.cc:393
#18 0x000055d162c98841 in Layout() () at ../../third_party/blink/renderer/core/layout/inline/inline_layout_algorithm.cc:1266
#19 0x000055d162c352d5 in Layout() () at ../../third_party/blink/renderer/core/layout/inline/inline_node.cc:1683
#20 0x000055d162e585e7 in LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:125
#21 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#22 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#23 0x000055d162e3cbde in LayoutWithSimpleInlineChildLayoutContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:599
#24 0x000055d162e3510a in LayoutInlineChild() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:592
#25 0x000055d162e34f7d in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:530
#26 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#27 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#28 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#29 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#30 0x000055d162e58683 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#31 LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:128
#32 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#33 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#34 0x000055d162e34f8f in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:532
#35 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#36 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#37 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#38 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#39 0x000055d162e58683 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#40 LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:128
#41 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#42 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#43 0x000055d162e34f8f in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:532
#44 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#45 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#46 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#47 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#48 0x000055d162e49807 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#49 LayoutNewFormattingContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:1940
#50 0x000055d162e46abd in HandleNewFormattingContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:1725
#51 0x000055d162e377dc in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:975
#52 0x000055d162e34f8f in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:532
#53 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#54 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#55 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#56 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#57 0x000055d16319de6f in LayoutRoot() () at ../../third_party/blink/renderer/core/layout/layout_view.cc:809
#58 0x000055d161f3df20 in PerformLayout() () at ../../third_party/blink/renderer/core/frame/local_frame_view.cc:783
#59 0x000055d161f40102 in UpdateLayout() () at ../../third_party/blink/renderer/core/frame/local_frame_view.cc:842
#60 0x000055d161f5cda3 in UpdateStyleAndLayoutInternal() () at ../../third_party/blink/renderer/core/frame/local_frame_view.cc:3177
#61 0x000055d161f48f36 in UpdateStyleAndLayout() () at ../../third_party/blink/renderer/core/frame/local_frame_view.cc:3107
#62 0x000055d164e4ac4c in UpdateStyleAndLayout() () at ../../third_party/blink/renderer/core/dom/document.cc:2827
#63 0x000055d164e5f8dc in ImplicitClose() () at ../../third_party/blink/renderer/core/dom/document.cc:3984
#64 0x000055d164e6068c in CheckCompletedInternal() () at ../../third_party/blink/renderer/core/dom/document.cc:4073
#65 0x000055d164e5ee93 in CheckCompleted() () at ../../third_party/blink/renderer/core/dom/document.cc:4035
#66 0x000055d1634a99ca in FinishedParsing() () at ../../third_party/blink/renderer/core/loader/frame_loader.cc:449
#67 0x000055d164e9a370 in FinishedParsing() () at ../../third_party/blink/renderer/core/dom/document.cc:7499
#68 0x000055d16517f773 in end () at ../../third_party/blink/renderer/core/html/parser/html_document_parser.cc:1075
#69 AttemptToRunDeferredScriptsAndEnd () at ../../third_party/blink/renderer/core/html/parser/html_document_parser.cc:1088
#70 PrepareToStopParsing() () at ../../third_party/blink/renderer/core/html/parser/html_document_parser.cc:566
#71 0x000055d16518524a in AttemptToEnd() () at ../../third_party/blink/renderer/core/html/parser/html_document_parser.cc:1112
#72 0x000055d16518011f in PumpTokenizerIfPossible() () at ../../third_party/blink/renderer/core/html/parser/html_document_parser.cc:651
#73 0x000055d1651808fb in DeferredPumpTokenizerIfPossible() () at ../../third_party/blink/renderer/core/html/parser/html_document_parser.cc:620
#74 0x000055d16519ebad in Invoke<void (blink::HTMLDocumentParser::*)(bool, base::TimeTicks), cppgc::internal::BasicPersistent<blink::HTMLDocumentParser, cppgc::internal::StrongPersistentPolicy, cppgc::internal::IgnoreLocationPolicy, cppgc::internal::DisabledCheckingPolicy>, bool, base::TimeTicks> () at ../../base/functional/bind_internal.h:738
#75 MakeItSo<void (blink::HTMLDocumentParser::*)(bool, base::TimeTicks), std::__Cr::tuple<cppgc::internal::BasicPersistent<blink::HTMLDocumentParser, cppgc::internal::StrongPersistentPolicy, cppgc::internal::IgnoreLocationPolicy, cppgc::internal::DisabledCheckingPolicy>, bool, base::TimeTicks> > () at ../../base/functional/bind_internal.h:930
#76 RunImpl<void (blink::HTMLDocumentParser::*)(bool, base::TimeTicks), std::__Cr::tuple<cppgc::internal::BasicPersistent<blink::HTMLDocumentParser, cppgc::internal::StrongPersistentPolicy, cppgc::internal::IgnoreLocationPolicy, cppgc::internal::DisabledCheckingPolicy>, bool, base::TimeTicks>, 0ul, 1ul, 2ul> () at ../../base/functional/bind_internal.h:1067
#77 RunOnce() () at ../../base/functional/bind_internal.h:980
#78 0x000055d154f98f45 in Run () at ../../base/functional/callback.h:156
#79 RunTaskImpl() () at ../../base/task/common/task_annotator.cc:203
#80 0x000055d155001057 in RunTask<(lambda at ../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:486:11)> () at ../../base/task/common/task_annotator.h:90
#81 DoWorkImpl() () at ../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:484
#82 0x000055d154fffdeb in DoWork() () at ../../base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:346
Reproduction Steps
- Use any Chromium starting from 129.0.6668.42 ASAN up until trunk.
- Set up a HTTP Server in the directory of the repro.
- Launch Chromium with the repro as usual
./chrome URL_TO/security_dcheck_reduced.html. - It should hit the
SECURITY_DCHECKmentioned on the Stack Trace.
Root Cause
SECURITY_DCHECK
The evaluation of the SECURITY_DCHECK is: SECURITY_DCHECK(length <= impl.length() - offset). The values at the invalid check when using the security_dcheck_reduced.html testcase are:
length: 0xffffffff
impl.length(): 0x3
offset: 0x1
At that moment, length has suffered an Integer Overflow.
The Integer Overflow
std::optional<LayoutUnit> ApplyJustificationInternal(
LayoutUnit space,
JustificationTarget target,
const LineInfo& line_info,
InlineItemResults* results) {
...
unsigned end_offset = line_info.EndOffsetForJustify(); //(A)
...
const unsigned line_text_start_offset =
line_info.Results().front().StartOffset(); //(B)
...
String line_text = BuildJustificationText(
text_content, line_info.Results(), line_text_start_offset, end_offset,
line_info.MayHaveTextCombineOrRubyItem()); //(C)
...
The variable end_offset (A) is assigned a value of 0, while line_text_start_offset (B) is set to 1. Both variables, end_offset (A) and line_text_start_offset (B), are passed as arguments to the BuildJustificationText (C) function.
String BuildJustificationText(const String& text_content,
const InlineItemResults& results,
unsigned line_text_start_offset,
unsigned end_offset,
bool may_have_text_combine_or_ruby) {
...
} else {
line_text_builder.Append(StringView(text_content,
line_text_start_offset,
end_offset - line_text_start_offset)); //(D) and (E)
}
...
The variables end_offset and line_text_start_offset are subtracted (D), resulting in a value of -1. As both are unsigned, the resulting value of 0xffffffff is passed to the StringView constructor (E).
inline StringView::StringView(const StringImpl* impl,
unsigned offset,
unsigned length) {
impl ? Set(*impl, offset, length) : Clear(); //(F)
}
The parameter length of StringView is set to 0xffffffff.
inline void StringView::Set(const StringImpl& impl,
unsigned offset,
unsigned length) { //(G)
...
SECURITY_DCHECK(length <= impl.length() - offset); //(H)
length_ = length;
...
}
StringView::Set receives it (G), triggering the SECURITY_DCHECK (H)
Integer Overflow: Root Cause
The LineInfo being computed is not updated before executing "Justification" operations, leading to a mismatch between the actions performed and the LineInfo involved.
This can be observed following the text_align_ member of the LineInfo being computed on the "Justification" operations. It contains the value of ETextAlign::kWebkitCenter but it should be ETextAlign::kJustify.
This is proved on EndOffsetForJustify method at line_info.h file, as the DCHECK_EQ (I) is hit by the testcase:
FATAL:line_info.h(211)] Check failed: text_align_ == ETextAlign::kJustify (-webkit-center vs. justify).
unsigned EndOffsetForJustify() const {
DCHECK_EQ(text_align_, ETextAlign::kJustify); //(I)
return end_offset_for_justify_;
}
This mismatch begins at ApplyRubyAlign function of ruby_utils.cc file:
std::pair<LayoutUnit, LayoutUnit> ApplyRubyAlign(LayoutUnit available_line_size,
bool on_start_edge,
bool on_end_edge,
LineInfo& line_info) {
...
ETextAlign text_align = line_info.TextAlign(); //(J)
...
case ERubyAlign::kSpaceBetween:
on_start_edge = true;
on_end_edge = true;
text_align = ETextAlign::kJustify; //(K)
break;
...
...
if (text_align == ETextAlign::kJustify) {
//(L)
...
std::optional<LayoutUnit> inset =
ApplyJustification(space, target, &line_info); //(M)
First, text_align (J) starts with the value ETextAlign::kWebkitCenter.
Second, text_align (K) value is modified, set as ETextAlign::kJustify.
Third, if condition is taken to peform Justification operations (L).
Fourth, a non-updated line_info is passed as argument (M), which mismatches with the Justification operations to be performed.
Resulting on the Integer Overflow described before.
The Patch
Proposal patch is attached as: line_info_int_overflow_proposal.patch
Before jumping into "Justification" operations (via ApplyJustification function), line_info should be updated by setting is_ruby_base_ and updating the "Text Align" to set a value to end_offset_for_justify_.
This can be performed by adding the calls to the methods: SetIsRubyBase (N) and UpdateTextAlign (O).
std::pair<LayoutUnit, LayoutUnit> ApplyRubyAlign(LayoutUnit available_line_size,
bool on_start_edge,
bool on_end_edge,
LineInfo& line_info) {
...
case ERubyAlign::kSpaceBetween:
on_start_edge = true;
on_end_edge = true;
text_align = ETextAlign::kJustify;
line_info.SetIsRubyBase(); //(N)
line_info.UpdateTextAlign(); //(O)
break;
...
Bisect: Introduced Commit
SECURITY_DCHECKintroduced at (Branch Base Position: 1340005) https://chromium.googlesource.com/chromium/src/+/ba40b993a6b700a2ad0fd092e141783fb1f60e70Integer Overflowintroduced on theRubyLB Featureat: (Branch Base Position: 1309784) https://chromium.googlesource.com/chromium/src/+/4edb29252ec52fade80d54f37c5bd18eedbf98cd but protected under flags:--enable-features=RubyLineBreakable,CssRubyAlign,RubyLineEdgeAlignment,RubyShortHeuristicsRubyLB Featureenabled at (Branch Base Position: 1312396) https://chromium.googlesource.com/chromium/src/+/71b76b57de06ee85121019c56e0a320dbae03073
Bisect: Introduced Major Chrome
Integer Overflow - Chrome Stable: 127.0.6533.57
SECURITY_DCHECK - Chrome Stable: 129.0.6668.42
VERSION
Chrome Version: [129.0.6668.42] + [stable] Operating System: [All]
REPRODUCTION CASE
Attached: security_dcheck_reduced.html
PATCH
Attached: line_info_int_overflow_proposal.patch
FOR CRASHES, PLEASE INCLUDE THE FOLLOWING ADDITIONAL INFORMATION
Type of crash: [Browser]
CREDIT INFORMATION
Reporter credit: Tashita Software Security
Context
This is a Chrome VRP report about an integer overflow in Blink's inline layout code, specifically in the justification path used by ruby annotations. The bug was reported by Tashita Software Security, rated high severity, and paid a bounty of 10,000.00 USD. It was disclosed on 2024-10-02 and is tracked as CVE-2024-7025.
The component is Layout. The crash the researcher observed is a Security DCHECK failure in string_view.h:
string_view.h Security DCHECK failed: length <= impl.length() - offset
The Security DCHECK was introduced in Chrome 129.0.6668.42, but the underlying integer overflow dates back to Chrome 127.0.6533.57. The report separates the two: the check is new, the bug is older.
Setup
The reproduction requires a Chromium build from 129.0.6668.42 (ASAN) up to trunk, an HTTP server serving the directory containing the repro file, and the repro file itself, security_dcheck_reduced.html. The crash is triggered during normal page load. The report notes the operating system as All.
Finding it
The researcher noticed a fatal security check failure with the following stack trace:
FATAL:string_view.h(351)] Security DCHECK failed: length <= impl.length() - offset.
#0 0x000055d154e663cc in ImmediateCrash () at ../../base/immediate_crash.h:176
#1 HandleFatal() () at ../../base/logging.cc:1073
#2 0x000055d154e6571e in operator() () at ../../base/logging.cc:773
#3 InvokeCallback () at ../../third_party/abseil-cpp/absl/cleanup/internal/cleanup.h:87
#4 ~Cleanup () at ../../third_party/abseil-cpp/absl/cleanup/cleanup.h:106
#5 Flush() () at ../../base/logging.cc:956
#6 0x000055d154e667d9 in ~LogMessageFatal() () at ../../base/logging.cc:1078
#7 0x000055d162f47b23 in Set () at ../../third_party/blink/renderer/platform/wtf/text/string_view.h:349
#8 StringView () at ../../third_party/blink/renderer/platform/wtf/text/string_view.h:326
#9 StringView () at ../../third_party/blink/renderer/platform/wtf/text/wtf_string.h:734
#10 BuildJustificationText() () at ../../third_party/blink/renderer/core/layout/inline/justification_utils.cc:78
#11 0x000055d162f45bce in ApplyJustificationInternal() () at ../../third_party/blink/renderer/core/layout/inline/justification_utils.cc:299
#12 0x000055d162fd966f in ApplyRubyAlign() () at ../../third_party/blink/renderer/core/layout/inline/ruby_utils.cc:455
#13 0x000055d162fafeed in PlaceRubyAnnotation() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:514
#14 0x000055d162fada02 in PlaceRubyColumn() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:500
#15 0x000055d162fa8d8c in HandleItemResults() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:175
#16 0x000055d162fa809d in CreateLine() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:72
#17 0x000055d162c8eacb in CreateLine() () at ../../third_party/blink/renderer/core/layout/inline/inline_layout_algorithm.cc:393
#18 0x000055d162c98841 in Layout() () at ../../third_party/blink/renderer/core/layout/inline/inline_layout_algorithm.cc:1266
#19 0x000055d162c352d5 in Layout() () at ../../third_party/blink/renderer/core/layout/inline/inline_node.cc:1683
#20 0x000055d162e585e7 in LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:125
#21 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#22 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#23 0x000055d162e3cbde in LayoutWithSimpleInlineChildLayoutContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:599
#24 0x000055d162e3510a in LayoutInlineChild() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:592
#25 0x000055d162e34f7d in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:530
#26 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#27 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#28 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#29 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#30 0x000055d162e58683 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#31 LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:128
#32 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#33 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#34 0x000055d162e34f8f in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:532
#35 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#36 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#37 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#38 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#39 0x000055d162e58683 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#40 LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:128
#41 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#42 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#43 0x000055d162e34f8f in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:532
#44 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#45 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#46 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#47 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#48 0x000055d162e49807 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#49 LayoutNewFormattingContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:1940
#50 0x000055d162e46abd in HandleNewFormattingContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:1725
#51 0x000055d162e377dc in Layout() () at ../../third_party/bl
The path runs from the HTML parser finishing parsing, through layout of the root, into block layout, into inline layout, into CreateLine, HandleItemResults, PlaceRubyColumn, PlaceRubyAnnotation, ApplyRubyAlign, ApplyJustificationInternal, and finally BuildJustificationText, where the StringView constructor trips the check.
Exploitation
Step 1: serve the repro
Set up an HTTP server in the directory containing the repro file.
Step 2: launch Chromium against it
./chrome URL_TO/security_dcheck_reduced.html
Step 3: observe the crash
The page load hits the SECURITY_DCHECK shown in the stack trace. The crash happens during the implicit close of the document, when layout is performed after parsing finishes, so simply loading the page is enough.
Root cause
The failing check is:
SECURITY_DCHECK(length <= impl.length() - offset)
At the point of failure with the reduced testcase, the values are:
length: 0xffffffff
impl.length(): 0x3
offset: 0x1
So length has already overflowed before it reaches the check.
The overflow is produced in ApplyJustificationInternal:
std::optional<LayoutUnit> ApplyJustificationInternal(
LayoutUnit space,
JustificationTarget target,
const LineInfo& line_info,
InlineItemResults* results) {
...
unsigned end_offset = line_info.EndOffsetForJustify(); //(A)
...
const unsigned line_text_start_offset =
line_info.Results().front().StartOffset(); //(B)
...
String line_text = BuildJustificationText(
text_content, line_info.Results(), line_text_start_offset, end_offset,
line_info.MayHaveTextCombineOrRubyItem()); //(C)
...
end_offset (A) is 0 and line_text_start_offset (B) is 1. Both are passed to BuildJustificationText (C):
String BuildJustificationText(const String& text_content,
const InlineItemResults& results,
unsigned line_text_start_offset,
unsigned end_offset,
bool may_have_text_combine_or_ruby) {
...
} else {
line_text_builder.Append(StringView(text_content,
line_text_start_offset,
end_offset - line_text_start_offset)); //(D) and (E)
}
...
The subtraction (D) of end_offset - line_text_start_offset is 0 - 1. Both operands are unsigned, so the result wraps to 0xffffffff, which is passed as the length to the StringView constructor (E):
inline StringView::StringView(const StringImpl* impl,
unsigned offset,
unsigned length) {
impl ? Set(*impl, offset, length) : Clear(); //(F)
}
Set receives the wrapped length (G) and the security check (H) fires:
inline void StringView::Set(const StringImpl& impl,
unsigned offset,
unsigned length) { //(G)
...
SECURITY_DCHECK(length <= impl.length() - offset); //(H)
length_ = length;
...
}
The deeper cause is that the LineInfo used for justification is not updated before the justification operations run, so the actions performed and the LineInfo state disagree. Following the text_align_ member shows it holds ETextAlign::kWebkitCenter when it should hold ETextAlign::kJustify. This is confirmed by the DCHECK_EQ in EndOffsetForJustify:
FATAL:line_info.h(211)] Check failed: text_align_ == ETextAlign::kJustify (-webkit-center vs. justify)
unsigned EndOffsetForJustify() const {
DCHECK_EQ(text_align_, ETextAlign::kJustify); //(I)
return end_offset_for_justify_;
}
The mismatch starts in ApplyRubyAlign:
std::pair<LayoutUnit, LayoutUnit> ApplyRubyAlign(LayoutUnit available_line_size,
bool on_start_edge,
bool on_end_edge,
LineInfo& line_info) {
...
ETextAlign text_align = line_info.TextAlign(); //(J)
...
case ERubyAlign::kSpaceBetween:
on_start_edge = true;
on_end_edge = true;
text_align = ETextAlign::kJustify; //(K)
break;
...
...
if (text_align == ETextAlign::kJustify) {
//(L)
...
std::optional<LayoutUnit> inset =
ApplyJustification(space, target, &line_info); //(M)
text_align (J) starts as ETextAlign::kWebkitCenter. In the ERubyAlign::kSpaceBetween case it is set to ETextAlign::kJustify (K), the justification branch is taken (L), and the unmodified line_info is passed to ApplyJustification (M). The justification code therefore runs with a LineInfo that still reflects the old alignment, and the offset arithmetic goes wrong.
Impact
The report describes the outcome as a browser crash: a fatal Security DCHECK failure during layout, reachable by loading a crafted page. It does not describe memory corruption or code execution.
Fix
The report attaches a proposal patch, line_info_int_overflow_proposal.patch. The fix is to update line_info before entering the justification operations, by setting is_ruby_base_ and updating the text alignment so that end_offset_for_justify_ gets a value. Concretely, the calls to SetIsRubyBase (N) and UpdateTextAlign (O) are added in the ERubyAlign::kSpaceBetween case:
std::pair<LayoutUnit, LayoutUnit> ApplyRubyAlign(LayoutUnit available_line_size,
bool on_start_edge,
bool on_end_edge,
LineInfo& line_info) {
...
case ERubyAlign::kSpaceBetween:
on_start_edge = true;
on_end_edge = true;
text_align = ETextAlign::kJustify;
line_info.SetIsRubyBase(); //(N)
line_info.UpdateTextAlign(); //(O)
break;
...
Variants to test
The report's bisect gives useful pointers for further testing:
- The integer overflow was introduced with the
RubyLB Featureat branch base position 1309784, but was protected under the flags--enable-features=RubyLineBreakable,CssRubyAlign,RubyLineEdgeAlignment,RubyShortHeuristics. - The
RubyLB Featurewas enabled by default at branch base position 1312396,
What happened, in plain words
A security researcher found a way to make Google Chrome crash by loading a specially crafted web page. The crash happens inside the part of Chrome that decides where text and small annotations sit on the screen. The bug is a type of mistake called an integer overflow, where a number that should be small ends up as a huge value because of how computers store numbers. The report attaches a proposal patch, and the details were made public on 2024-10-02. The bug is tracked as CVE-2024-7025.
The report was filed through the Chrome VRP. VRP stands for Vulnerability Reward Program: a scheme where Google pays people who privately report security bugs in Chrome, so the bugs can be fixed before bad people find them. The researcher is credited as Tashita Software Security, and the severity was rated high.
The affected component is Layout. Layout is the step where the browser works out the size and position of everything on a page: how wide a paragraph is, where each line of text starts, where a small pronunciation guide above a character should sit. If layout gets its numbers wrong, the browser can misbehave, and in this case it deliberately stops itself with a fatal error rather than carry on with bad data.
The crash the researcher saw is a failed Security DCHECK in a file called string_view.h:
string_view.h Security DCHECK failed: length <= impl.length() - offset
A DCHECK is a debug check: an assertion that the code writes into itself to say "this condition must always be true". A Security DCHECK is a check that fires when something security-relevant has gone wrong. When it fails, Chrome crashes on purpose. The message above says: the length we were asked to use is bigger than the space actually available in the string.
The report makes an important distinction: the check that catches the problem was only added in Chrome 129.0.6668.42, but the underlying integer overflow had been in Chrome since 127.0.6533.57. In other words, the bug is older than the alarm that now goes off when it is triggered.
Setup
To reproduce the crash you need three things, according to the report:
- A Chromium build from version 129.0.6668.42 (an ASAN build) up to the latest development version, called trunk. Chromium is the open-source project Chrome is built from. ASAN stands for AddressSanitizer, a tool that adds extra checks to a program while it runs, which makes bugs easier to spot during testing.
- A simple HTTP server running in the folder that contains the reproduction file. An HTTP server is a small program that hands files to a browser over the network when the browser asks for them by address. You need one because the browser loads the test page the same way it would load a real website.
- The reproduction file itself, named
security_dcheck_reduced.html. The report attaches it but does not show its contents.
The crash happens during a normal page load. The report lists the operating system as All, meaning it is not tied to one platform.
Finding it
The researcher noticed a fatal security check failure and captured the following message:
FATAL:string_view.h(351)] Security DCHECK failed: length <= impl.length() - offset.
FATAL means the program is about to stop. The rest names the file and line where the check lives and quotes the condition that failed.
Alongside it, the researcher captured a stack trace:
#0 0x000055d154e663cc in ImmediateCrash () at ../../base/immediate_crash.h:176
#1 HandleFatal() () at ../../base/logging.cc:1073
#2 0x000055d154e6571e in operator() () at ../../base/logging.cc:773
#3 InvokeCallback () at ../../third_party/abseil-cpp/absl/cleanup/internal/cleanup.h:87
#4 ~Cleanup () at ../../third_party/abseil-cpp/absl/cleanup/cleanup.h:106
#5 Flush() () at ../../base/logging.cc:956
#6 0x000055d154e667d9 in ~LogMessageFatal() () at ../../base/logging.cc:1078
#7 0x000055d162f47b23 in Set () at ../../third_party/blink/renderer/platform/wtf/text/string_view.h:349
#8 StringView () at ../../third_party/blink/renderer/platform/wtf/text/string_view.h:326
#9 StringView () at ../../third_party/blink/renderer/platform/wtf/text/wtf_string.h:734
#10 BuildJustificationText() () at ../../third_party/blink/renderer/core/layout/inline/justification_utils.cc:78
#11 0x000055d162f45bce in ApplyJustificationInternal() () at ../../third_party/blink/renderer/core/layout/inline/justification_utils.cc:299
#12 0x000055d162fd966f in ApplyRubyAlign() () at ../../third_party/blink/renderer/core/layout/inline/ruby_utils.cc:455
#13 0x000055d162fafeed in PlaceRubyAnnotation() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:514
#14 0x000055d162fada02 in PlaceRubyColumn() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:500
#15 0x000055d162fa8d8c in HandleItemResults() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:175
#16 0x000055d162fa809d in CreateLine() () at ../../third_party/blink/renderer/core/layout/inline/logical_line_builder.cc:72
#17 0x000055d162c8eacb in CreateLine() () at ../../third_party/blink/renderer/core/layout/inline/inline_layout_algorithm.cc:393
#18 0x000055d162c98841 in Layout() () at ../../third_party/blink/renderer/core/layout/inline/inline_layout_algorithm.cc:1266
#19 0x000055d162c352d5 in Layout() () at ../../third_party/blink/renderer/core/layout/inline/inline_node.cc:1683
#20 0x000055d162e585e7 in LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:125
#21 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#22 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#23 0x000055d162e3cbde in LayoutWithSimpleInlineChildLayoutContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:599
#24 0x000055d162e3510a in LayoutInlineChild() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:592
#25 0x000055d162e34f7d in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:530
#26 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#27 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#28 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#29 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#30 0x000055d162e58683 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#31 LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:128
#32 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#33 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#34 0x000055d162e34f8f in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:532
#35 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#36 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#37 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#38 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#39 0x000055d162e58683 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#40 LayoutInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:128
#41 0x000055d162e57a52 in HandleInflow() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:2126
#42 0x000055d162e376f2 in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:980
#43 0x000055d162e34f8f in Layout() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:532
#44 0x000055d162d4cc29 in operator()<blink::BlockLayoutAlgorithm> () at ../../third_party/blink/renderer/core/layout/block_node.cc:214
#45 CreateAlgorithmAndRun<blink::BlockLayoutAlgorithm, (lambda at ../../third_party/blink/renderer/core/layout/block_node.cc:213:28)>(void) () at ../../third_party/blink/renderer/core/layout/block_node.cc:120
#46 0x000055d162d338c1 in LayoutWithAlgorithm () at ../../third_party/blink/renderer/core/layout/block_node.cc:212
#47 Layout() () at ../../third_party/blink/renderer/core/layout/block_node.cc:523
#48 0x000055d162e49807 in LayoutBlockChild () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:113
#49 LayoutNewFormattingContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:1940
#50 0x000055d162e46abd in HandleNewFormattingContext() () at ../../third_party/blink/renderer/core/layout/block_layout_algorithm.cc:1725
#51 0x000055d162e377dc in Layout() () at ../../third_party/bl
A stack trace is a list of the functions that were running at the moment of the crash, newest first. Frame #0 is where the program stopped; each later frame is the function that called the one above it. Reading from the bottom up tells the story of how the browser got there:
- The HTML parser, the part that reads the page's markup, finishes parsing (
FinishedParsing,end,AttemptToEnd). - The document is implicitly closed (
ImplicitClose), which triggers a style and layout update (UpdateStyleAndLayout,PerformLayout,LayoutRoot). - Layout descends through block layout (
BlockLayoutAlgorithm,LayoutBlockChild,LayoutInflow) and then into inline layout, the part that arranges text within a line (InlineLayoutAlgorithm,CreateLine). - Inside line building, ruby handling runs:
HandleItemResults,PlaceRubyColumn,PlaceRubyAnnotation,ApplyRubyAlign. - Ruby alignment calls justification:
ApplyJustificationInternal, thenBuildJustificationText. - There, a
StringViewis constructed (StringView,Set) and the security check fires.
The appearance of ruby annotation placement in the trace is the first hint that the bug lives in the ruby alignment and justification code. Ruby is a small annotation printed above or beside text, commonly used in Japanese and Chinese to show pronunciation. Justification is the stretching or squeezing of a line so it lines up neatly at both edges.
Exploitation
Step 1: serve the repro
Set up an HTTP server in the directory containing the repro file. This makes the test page reachable at a normal web address.
Step 2: launch Chromium against it
./chrome URL_TO/security_dcheck_reduced.html
This line starts the Chromium program (./chrome) and gives it the address of the test page as its argument.
Step 3: observe the crash
The page load hits the SECURITY_DCHECK shown in the stack trace. The crash happens during the implicit close of the document, when layout is performed after parsing finishes, so simply loading the page is enough.
Root cause
The failing check is:
SECURITY_DCHECK(length <= impl.length() - offset)
In plain words: the length of the piece of text we want to look at must not be larger than the room left in the underlying string after skipping offset characters. At the point of failure with the reduced testcase, the values are:
length: 0xffffffff
impl.length(): 0x3
offset: 0x1
0xffffffff is how programmers write the largest value a 32-bit unsigned number can hold (4,294,967,295 in decimal). impl.length() is 3 and offset is 1, so the right-hand side is 2. A length of about four billion is obviously far bigger than 2, so the check fails. The key point is that length has already overflowed before it reaches the check.
The overflow is produced in ApplyJustificationInternal:
std::optional<LayoutUnit> ApplyJustificationInternal(
LayoutUnit space,
JustificationTarget target,
const LineInfo& line_info,
InlineItemResults* results) {
...
unsigned end_offset = line_info.EndOffsetForJustify(); //(A)
...
const unsigned line_text_start_offset =
line_info.Results().front().StartOffset(); //(B)
...
String line_text = BuildJustificationText(
text_content, line_info.Results(), line_text_start_offset, end_offset,
line_info.MayHaveTextCombineOrRubyItem()); //(C)
...
Line by line:
- The function takes a
spaceamount to distribute, atargetsaying what is being justified, aLineInfoobject describing the line, and a pointer to the results of laying out the line's items. unsigned end_offset = line_info.EndOffsetForJustify();(A) asks the line information where the text to justify ends.unsignedmeans a whole number that cannot be negative; it wraps around to a huge value if you try to go below zero. Here it comes back as 0.const unsigned line_text_start_offset = line_info.Results().front().StartOffset();(B) asks where the first laid-out item on the line starts. Here it comes back as 1.BuildJustificationText(...)(C) is then called with both numbers, plus the text content and the line's results.
So end_offset (A) is 0 and line_text_start_offset (B) is 1. Both are passed to BuildJustificationText (C):
String BuildJustificationText(const String& text_content,
const InlineItemResults& results,
unsigned line_text_start_offset,
unsigned end_offset,
bool may_have_text_combine_or_ruby) {
...
} else {
line_text_builder.Append(StringView(text_content,
line_text_start_offset,
end_offset - line_text_start_offset)); //(D) and (E)
}
...
Line by line:
- The function receives the full text, the line's results, the start offset, the end offset, and a flag saying whether the line might contain text-combine or ruby items.
- In the
elsebranch, it builds aStringViewovertext_content, starting atline_text_start_offsetand takingend_offset - line_text_start_offsetcharacters (D). AStringViewis a lightweight window onto an existing string: it does not copy the text, it just remembers where to start and how many characters to show. - The subtraction (D) is
0 - 1. Both operands areunsigned, so the result wraps around to0xffffffffinstead of -1. That wrapped value is passed as the length to theStringViewconstructor (E).
Think of it like a ruler with no negative numbers: if you are told to measure from mark 1 back to mark 0, you cannot write -1, so the ruler rolls over to its largest possible marking.
inline StringView::StringView(const StringImpl* impl,
unsigned offset,
unsigned length) {
impl ? Set(*impl, offset, length) : Clear(); //(F)
}
Line by line:
- The constructor takes a pointer to the underlying string, an offset and a length.
- If the pointer is not null, it calls
Setwith those values (F); otherwise it clears the view. Here the pointer is valid, soSetis called with the wrapped length.
Set receives the wrapped length (G) and the security check (H) fires:
inline void StringView::Set(const StringImpl& impl,
unsigned offset,
unsigned length) { //(G)
...
SECURITY_DCHECK(length <= impl.length() - offset); //(H)
length_ = length;
...
}
Line by line:
Setis given the underlying string, the offset and the length (G).- The security check (H) compares the requested length against the room left in the string. With a length of
0xffffffffand only 2 characters of room, it fails and Chrome crashes before storing the bad length.
The deeper cause is that the LineInfo used for justification is not updated before the justification operations run, so the actions performed and the LineInfo state disagree. Following the text_align_ member shows it holds ETextAlign::kWebkitCenter when it should hold ETextAlign::kJustify. text_align_ is the line's text alignment setting; -webkit-center centres text, while justify stretches it to both edges. This is confirmed by the DCHECK_EQ in EndOffsetForJustify:
FATAL:line_info.h(211)] Check failed: text_align_ == ETextAlign::kJustify (-webkit-center vs. justify)
unsigned EndOffsetForJustify() const {
DCHECK_EQ(text_align_, ETextAlign::kJustify); //(I)
return end_offset_for_justify_;
}
Line by line:
EndOffsetForJustifyis supposed to return the end offset used for justification.DCHECK_EQ(text_align_, ETextAlign::kJustify);(I) asserts that the line's alignment really is justify. The message above shows it was-webkit-centerinstead, so the assertion fails in debug builds.- It then returns
end_offset_for_justify_.
The mismatch starts in ApplyRubyAlign:
std::pair<LayoutUnit, LayoutUnit> ApplyRubyAlign(LayoutUnit available_line_size,
bool on_start_edge,
bool on_end_edge,
LineInfo& line_info) {
...
ETextAlign text_align = line_info.TextAlign(); //(J)
...
case ERubyAlign::kSpaceBetween:
on_start_edge = true;
on_end_edge = true;
text_align = ETextAlign::kJustify; //(K)
break;
...
...
if (text_align == ETextAlign::kJustify) {
//(L)
...
std::optional<LayoutUnit> inset =
ApplyJustification(space, target, &line_info); //(M)
Line by line:
- The function receives the available line size, two flags about the start and end edges, and a reference to the
LineInfo. ETextAlign text_align = line_info.TextAlign();(J) reads the line's current alignment into a local variable. It starts asETextAlign::kWebkitCenter.- In the
ERubyAlign::kSpaceBetweencase, the code sets both edge flags to true and changes the localtext_aligntoETextAlign::kJustify(K).ERubyAlign::kSpaceBetweenis a ruby alignment mode that spreads the annotation out to fill the space. - The
if (text_align == ETextAlign::kJustify)branch is then taken (L), because the local variable now says justify. ApplyJustification(space, target, &line_info);(M) is called with the originalline_info, which still says-webkit-center. The local variable was changed, but theLineInfoobject itself was not.
So the justification code runs with a LineInfo that still reflects the old alignment, and the offset arithmetic goes wrong. The local variable and the shared object disagree, and the code acts on the local variable while reading numbers from the shared object.
Impact
The report describes the outcome as a browser crash: a fatal Security DCHECK failure during layout, reachable by loading a crafted page. It does not describe memory corruption or code execution.
Fix
The report attaches a proposal patch, line_info_int_overflow_proposal.patch. The fix is to update line_info before entering the justification operations, by setting is_ruby_base_ and updating the text alignment so that end_offset_for_justify_ gets a value. Concretely, the calls to SetIsRubyBase (N) and UpdateTextAlign (O) are added in the ERubyAlign::kSpaceBetween case:
std::pair<LayoutUnit, LayoutUnit> ApplyRubyAlign(LayoutUnit available_line_size,
bool on_start_edge,
bool on_end_edge,
LineInfo& line_info) {
...
case ERubyAlign::kSpaceBetween:
on_start_edge = true;
on_end_edge = true;
text_align = ETextAlign::kJustify;
line_info.SetIsRubyBase(); //(N)
line_info.UpdateTextAlign(); //(O)
break;
...
Line by line:
- The
ERubyAlign::kSpaceBetweencase still sets both edge flags and the localtext_alignto justify. line_info.SetIsRubyBase();(N) marks the line information as a ruby base, so later code knows it is dealing with ruby.line_info.UpdateTextAlign();(O) updates the line information's own alignment to match the local variable, which also setsend_offset_for_justify_to a correct value.
Variants to test
The report's bisect gives useful pointers for further testing. A bisect is a search that narrows down which change introduced a bug by testing versions in the middle of a range and halving the range each time.
- The integer overflow was introduced with the
RubyLB Featureat branch base position 1309784, but was protected under the flags--enable-features=RubyLineBreakable,CssRubyAlign,RubyLineEdgeAlignment,RubyShortHeuristics. - The
RubyLB Featurewas enabled by default at branch base position 1312396,
Glossary
- API: a defined way for one piece of software to ask another piece of software to do something, like a menu of allowed requests.
- ASAN (AddressSanitizer): a tool built into a test version of a program that watches memory use and stops the program when it sees something suspicious, making bugs easier to find.
- Bisect: a search technique that finds the change that introduced a bug by testing versions in the middle of a range and halving the range each time.
- Blink: the rendering engine inside Chrome that turns HTML, CSS and scripts into what you see on screen.
- Bounty: money paid to a researcher who reports a security bug privately so it can be fixed.
- Branch base position: a number identifying a point in the project's history, used to refer to a specific change.
- Chrome VRP (Vulnerability Reward Program): Google's scheme that pays people for privately reporting security bugs in Chrome.
- Chromium: the open-source browser project that Google Chrome is built from.
- Component: the part of the browser a bug affects, here Layout.
- Crash: when a program stops unexpectedly because it hit an error it cannot continue past.
- CVE: a public identifier for a known security vulnerability, here CVE-2024-7025.
- DCHECK: a debug assertion written into the code that must always be true; if it fails, the program stops.
- Debug build: a version of a program compiled with extra checks and logging for testing.
- Document: the browser's internal representation of a loaded web page.
- DOM: the tree of elements that makes up a web page, which the browser reads and lays out.
- ETextAlign: an internal setting describing how text is aligned, such as centred or justified.
- ERubyAlign: an internal setting describing how ruby annotations are aligned.
- FATAL: a log level meaning the program is about to stop.
- Frame (stack frame): one entry in a stack trace, showing a function that was running.
- HTML parser: the part of the browser that reads the page's markup and builds the document from it.
- HTTP server: a program that hands files to a browser over the network when asked by address.
- Inline layout: the part of layout that arranges text and inline items within a line.
- Integer overflow: when a number grows past the largest value its storage type can hold and wraps around to a small or unexpected value.
- Justification: stretching or squeezing a line of text so it lines up neatly at both edges.
- Layout: the step where the browser works out the size and position of everything on a page.
- LayoutUnit: an internal number type used for layout measurements.
- LineInfo: an internal object holding information about a line being laid out, including its alignment and offsets.
- Patch: a proposed change to the source code that fixes a bug.
- Repro (reproduction case): a file or set of steps that reliably triggers a bug.
- Ruby: a small annotation printed above or beside text, often used to show pronunciation.
- RubyLB Feature: a Chrome feature related to ruby line breaking, which can be switched on or off with flags.
- Security DCHECK: a debug check that Chrome keeps switched on in normal builds because a failure means something security-relevant went wrong.
- Severity: a rating of how serious a bug is, here high.
- Stack trace: a list of the functions that were running at the moment of a crash, newest first.
- StringView: a lightweight window onto an existing string that records a start offset and a length without copying the text.
- Trunk: the latest development version of a project's source code.
- Unsigned: a whole-number type that cannot be negative and wraps around to a huge value if you try to go below zero.
- Vulnerability: a weakness in software that can be triggered to make it behave in a way its authors did not intend, often with security consequences.
- Webkit-center: a text alignment value that centres text, written
-webkit-centerin CSS.