Skip to content

Commit

Permalink
#1914 で確認した問題への対策を追加 (#1966)
Browse files Browse the repository at this point in the history
* CRuler::DrawRulerBg メソッドで nMaxLineKetas (10240) より keta の値が大きくなる為に結果的に負の値が size_t 型のローカル変数に代入され、極端に大きい値が std::vector::resize メソッドに渡されてしまう問題への対策を追加 

* CFigure_Comma::DispSpace で ExtTextOut を呼び出す際に szViewString の文字数が 64 を超過すると pMetrics->GetDxArray_AllHankaku() で取得する領域の範囲外参照が発生する問題への対策を追加
  • Loading branch information
beru authored Jul 18, 2024
1 parent ea735b6 commit fe4cc6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sakura_core/view/CRuler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void CRuler::DrawRulerBg(CGraphics& gr)

// 目盛り線を1本ずつ描画するのではなく後述する PolyPolyline でまとめて描画を行う
const int nWidth = (Int)(m_pEditView->GetTextArea().GetRightCol() - i);
const size_t nLinesToDraw = 1 + std::min<int>((nWidth + 1 + 1 + oneColumn - 1) / oneColumn, nMaxLineKetas - keta + 1);
const size_t nLinesToDraw = 1 + std::min<int>((nWidth + 1 + 1 + oneColumn - 1) / oneColumn, std::max(nMaxLineKetas - keta, 0) + 1);
auto& apt = m_apt;
auto& asz = m_asz;
apt.resize(nLinesToDraw * 2);
Expand Down
10 changes: 9 additions & 1 deletion sakura_core/view/figures/CFigure_Comma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ void CFigure_Comma::DispSpace(CGraphics& gr, DispPos* pDispPos, CEditView* pcVie
if (szViewString.length() < nTabDispWidth) {
szViewString.append(nTabDispWidth - szViewString.length(), L' ');
}
const INT* lpDx;
if( szViewString.length() > 64 ) {
static std::vector<int> anHankakuDx; //!< 半角用文字間隔配列
anHankakuDx.resize(szViewString.length(), pMetrics->GetHankakuDx());
lpDx = &anHankakuDx[0];
}else {
lpDx = pMetrics->GetDxArray_AllHankaku();
}
::ExtTextOut(
gr,
sPos.GetDrawPos().x,
Expand All @@ -98,7 +106,7 @@ void CFigure_Comma::DispSpace(CGraphics& gr, DispPos* pDispPos, CEditView* pcVie
&rcClip2,
szViewString.c_str(),
static_cast<UINT>(szViewString.length()),
pMetrics->GetDxArray_AllHankaku()
lpDx
);
}
}
Expand Down

0 comments on commit fe4cc6d

Please sign in to comment.