Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Side by Side Diff: xfa/fde/css/fde_csssyntax.cpp

Issue 2535663003: Fix crash in CFDE_CSSSyntaxParser when parsing empty url (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fde/css/fde_csssyntax.h" 7 #include "xfa/fde/css/fde_csssyntax.h"
8 8
9 #include <algorithm>
10
9 #include "xfa/fde/css/fde_cssdatatable.h" 11 #include "xfa/fde/css/fde_cssdatatable.h"
10 #include "xfa/fgas/crt/fgas_codepage.h" 12 #include "xfa/fgas/crt/fgas_codepage.h"
11 13
12 namespace { 14 namespace {
13 15
14 bool FDE_IsSelectorStart(FX_WCHAR wch) { 16 bool FDE_IsSelectorStart(FX_WCHAR wch) {
15 return wch == '.' || wch == '#' || wch == '*' || (wch >= 'a' && wch <= 'z') || 17 return wch == '.' || wch == '#' || wch == '*' || (wch >= 'a' && wch <= 'z') ||
16 (wch >= 'A' && wch <= 'Z'); 18 (wch >= 'A' && wch <= 'Z');
17 } 19 }
18 20
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 break; 275 break;
274 } 276 }
275 break; 277 break;
276 case FDE_CSSSYNTAXMODE_URI: { 278 case FDE_CSSSYNTAXMODE_URI: {
277 FDE_CSSSYNTAXMODE* pMode = m_ModeStack.GetTopElement(); 279 FDE_CSSSYNTAXMODE* pMode = m_ModeStack.GetTopElement();
278 if (!pMode || *pMode != FDE_CSSSYNTAXMODE_Import) 280 if (!pMode || *pMode != FDE_CSSSYNTAXMODE_Import)
279 return m_eStatus = FDE_CSSSYNTAXSTATUS_Error; 281 return m_eStatus = FDE_CSSSYNTAXSTATUS_Error;
280 282
281 if (wch <= ' ' || wch == ';') { 283 if (wch <= ' ' || wch == ';') {
282 int32_t iURIStart, iURILength = m_TextData.GetLength(); 284 int32_t iURIStart, iURILength = m_TextData.GetLength();
283 if (iURILength > 0 && 285 if (iURILength > 0 && FDE_ParseCSSURI(m_TextData.GetBuffer(),
284 FDE_ParseCSSURI(m_TextData.GetBuffer(), iURILength, iURIStart, 286 &iURIStart, &iURILength)) {
285 iURILength)) {
286 m_TextData.Subtract(iURIStart, iURILength); 287 m_TextData.Subtract(iURIStart, iURILength);
287 SwitchMode(FDE_CSSSYNTAXMODE_MediaType); 288 SwitchMode(FDE_CSSSYNTAXMODE_MediaType);
288 if (IsImportEnabled()) { 289 if (IsImportEnabled())
289 return FDE_CSSSYNTAXSTATUS_URI; 290 return FDE_CSSSYNTAXSTATUS_URI;
290 } else { 291 else
Tom Sepez 2016/11/28 19:24:40 nit: else after return not needed.
npm 2016/11/28 20:35:45 Done.
291 break; 292 break;
292 }
293 } 293 }
294 } 294 }
295 AppendChar(wch); 295 AppendChar(wch);
296 } break; 296 } break;
297 case FDE_CSSSYNTAXMODE_AtRule: 297 case FDE_CSSSYNTAXMODE_AtRule:
298 if (wch > ' ') { 298 if (wch > ' ') {
299 AppendChar(wch); 299 AppendChar(wch);
300 } else { 300 } else {
301 int32_t iLen = m_TextData.GetLength(); 301 int32_t iLen = m_TextData.GetLength();
302 const FX_WCHAR* psz = m_TextData.GetBuffer(); 302 const FX_WCHAR* psz = m_TextData.GetBuffer();
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } else { 461 } else {
462 return true; 462 return true;
463 } 463 }
464 if (!m_pBuffer) { 464 if (!m_pBuffer) {
465 m_iBufLen = 0; 465 m_iBufLen = 0;
466 return false; 466 return false;
467 } 467 }
468 m_iBufLen = iDesiredSize; 468 m_iBufLen = iDesiredSize;
469 return true; 469 return true;
470 } 470 }
471
471 void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) { 472 void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) {
472 ASSERT(iStart >= 0 && iLength > 0); 473 ASSERT(iStart >= 0 && iLength >= 0);
473 if (iLength > m_iDatLen - iStart) { 474 iLength = std::max(std::min(iLength, m_iDatLen - iStart), 0);
474 iLength = m_iDatLen - iStart; 475 FXSYS_memmove(m_pBuffer, m_pBuffer + iStart, iLength * sizeof(FX_WCHAR));
475 }
476 if (iLength < 0) {
477 iLength = 0;
478 } else {
479 FXSYS_memmove(m_pBuffer, m_pBuffer + iStart, iLength * sizeof(FX_WCHAR));
480 }
481 m_iDatLen = iLength; 476 m_iDatLen = iLength;
482 } 477 }
OLDNEW
« xfa/fde/css/fde_cssdatatable.cpp ('K') | « xfa/fde/css/fde_cssdeclaration.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698