Commit fa863b6e authored by Abigail Klein's avatar Abigail Klein Committed by Commit Bot

[Live Caption] Speculative fix of a crash in GetNumLinesInLabel.

An EXCEPTION_ACCESS_VIOLATION_READ crash was reported in
CaptionBubble::GetNumLinesInLabel. I believe the cause is that
CaptionBubble::GetNumLinesInLabel calls Label::GetRequiredLines, which
is a const function. To fix this, I mark
CaptionBubble::GetNumLinesInLabel as const.

While I am here, I am also performing a check that observer_ is not
null in CaptionBubbleModel::CommitPartialText, which would cause a
different crash.

Bug: 1055150, 1096366
Change-Id: Ic039de789f4ce5dc34b3dff0ee11e38bcfabb4b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252198
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780003}
parent f9696375
...@@ -536,7 +536,7 @@ size_t CaptionBubble::GetTextIndexOfLineInLabel(size_t line) const { ...@@ -536,7 +536,7 @@ size_t CaptionBubble::GetTextIndexOfLineInLabel(size_t line) const {
return label_->GetTextIndexOfLine(line); return label_->GetTextIndexOfLine(line);
} }
size_t CaptionBubble::GetNumLinesInLabel() { size_t CaptionBubble::GetNumLinesInLabel() const {
return label_->GetRequiredLines(); return label_->GetRequiredLines();
} }
......
...@@ -60,7 +60,7 @@ class CaptionBubble : public views::BubbleDialogDelegateView, ...@@ -60,7 +60,7 @@ class CaptionBubble : public views::BubbleDialogDelegateView,
size_t GetTextIndexOfLineInLabel(size_t line) const; size_t GetTextIndexOfLineInLabel(size_t line) const;
// Returns the number of lines in the caption bubble label that are rendered. // Returns the number of lines in the caption bubble label that are rendered.
size_t GetNumLinesInLabel(); size_t GetNumLinesInLabel() const;
const char* GetClassName() const override; const char* GetClassName() const override;
......
...@@ -89,12 +89,15 @@ void CaptionBubbleModel::CommitPartialText() { ...@@ -89,12 +89,15 @@ void CaptionBubbleModel::CommitPartialText() {
} }
partial_text_.clear(); partial_text_.clear();
if (!observer_)
return;
// Truncate the final text to kMaxLines lines long. This time, alert the // Truncate the final text to kMaxLines lines long. This time, alert the
// observer that the text has changed. // observer that the text has changed.
const size_t num_lines = observer_->GetNumLinesInLabel(); const size_t num_lines = observer_->GetNumLinesInLabel();
if (num_lines > kMaxLines) { if (num_lines > kMaxLines) {
DCHECK(base::IsStringASCII(final_text_)); DCHECK(base::IsStringASCII(final_text_));
size_t truncate_index = const size_t truncate_index =
observer_->GetTextIndexOfLineInLabel(num_lines - kMaxLines); observer_->GetTextIndexOfLineInLabel(num_lines - kMaxLines);
final_text_.erase(0, truncate_index); final_text_.erase(0, truncate_index);
OnTextChange(); OnTextChange();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment