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

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

Issue 2535663003: Fix crash in CFDE_CSSSyntaxParser when parsing empty url (Closed)
Patch Set: Comments 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
« no previous file with comments | « xfa/fde/css/fde_cssdeclaration.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 break;
291 break;
292 }
293 } 292 }
294 } 293 }
295 AppendChar(wch); 294 AppendChar(wch);
296 } break; 295 } break;
297 case FDE_CSSSYNTAXMODE_AtRule: 296 case FDE_CSSSYNTAXMODE_AtRule:
298 if (wch > ' ') { 297 if (wch > ' ') {
299 AppendChar(wch); 298 AppendChar(wch);
300 } else { 299 } else {
301 int32_t iLen = m_TextData.GetLength(); 300 int32_t iLen = m_TextData.GetLength();
302 const FX_WCHAR* psz = m_TextData.GetBuffer(); 301 const FX_WCHAR* psz = m_TextData.GetBuffer();
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } else { 460 } else {
462 return true; 461 return true;
463 } 462 }
464 if (!m_pBuffer) { 463 if (!m_pBuffer) {
465 m_iBufLen = 0; 464 m_iBufLen = 0;
466 return false; 465 return false;
467 } 466 }
468 m_iBufLen = iDesiredSize; 467 m_iBufLen = iDesiredSize;
469 return true; 468 return true;
470 } 469 }
470
471 void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) { 471 void CFDE_CSSTextBuf::Subtract(int32_t iStart, int32_t iLength) {
472 ASSERT(iStart >= 0 && iLength > 0); 472 ASSERT(iStart >= 0 && iLength >= 0);
473 if (iLength > m_iDatLen - iStart) { 473 iLength = std::max(std::min(iLength, m_iDatLen - iStart), 0);
474 iLength = m_iDatLen - iStart; 474 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; 475 m_iDatLen = iLength;
482 } 476 }
OLDNEW
« no previous file with comments | « xfa/fde/css/fde_cssdeclaration.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698