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

Side by Side Diff: core/fpdfapi/page/cpdf_streamparser.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: Plug leaks Created 4 years, 1 month 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "core/fpdfapi/page/pageint.h" 7 #include "core/fpdfapi/page/pageint.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 10
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 m_Pos = dwPrevPos; 223 m_Pos = dwPrevPos;
224 break; 224 break;
225 } 225 }
226 dwStreamSize += m_Pos - dwPrevPos; 226 dwStreamSize += m_Pos - dwPrevPos;
227 } 227 }
228 m_Pos = dwSavePos; 228 m_Pos = dwSavePos;
229 pData = FX_Alloc(uint8_t, dwStreamSize); 229 pData = FX_Alloc(uint8_t, dwStreamSize);
230 FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize); 230 FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize);
231 m_Pos += dwStreamSize; 231 m_Pos += dwStreamSize;
232 } 232 }
233 pDict->SetIntegerFor("Length", (int)dwStreamSize); 233 pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize);
234 return new CPDF_Stream(pData, dwStreamSize, pDict); 234 return new CPDF_Stream(pData, dwStreamSize, pDict);
235 } 235 }
236 236
237 CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() { 237 CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() {
238 delete m_pLastObj; 238 delete m_pLastObj;
239 m_pLastObj = nullptr; 239 m_pLastObj = nullptr;
240 240
241 m_WordSize = 0; 241 m_WordSize = 0;
242 bool bIsNumber = true; 242 bool bIsNumber = true;
243 if (!PositionIsInBounds()) 243 if (!PositionIsInBounds())
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 341
342 if (first_char == '(') { 342 if (first_char == '(') {
343 CFX_ByteString str = ReadString(); 343 CFX_ByteString str = ReadString();
344 return new CPDF_String(m_pPool, str, false); 344 return new CPDF_String(m_pPool, str, false);
345 } 345 }
346 346
347 if (first_char == '<') { 347 if (first_char == '<') {
348 if (m_WordSize == 1) 348 if (m_WordSize == 1)
349 return new CPDF_String(m_pPool, ReadHexString(), true); 349 return new CPDF_String(m_pPool, ReadHexString(), true);
350 350
351 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pPool); 351 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pPool);
Lei Zhang 2016/11/18 04:14:20 For later: unique_ptr.
352 while (1) { 352 while (1) {
353 GetNextWord(bIsNumber); 353 GetNextWord(bIsNumber);
354 if (m_WordSize == 2 && m_WordBuffer[0] == '>') 354 if (m_WordSize == 2 && m_WordBuffer[0] == '>')
355 break; 355 break;
356 356
357 if (!m_WordSize || m_WordBuffer[0] != '/') { 357 if (!m_WordSize || m_WordBuffer[0] != '/') {
358 delete pDict; 358 delete pDict;
359 return nullptr; 359 return nullptr;
360 } 360 }
361 361
362 CFX_ByteString key = 362 CFX_ByteString key =
363 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); 363 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1));
364 CPDF_Object* pObj = ReadNextObject(true, 0); 364 auto pObj = pdfium::WrapUnique(ReadNextObject(true, 0));
365 if (!pObj) { 365 if (!pObj) {
366 delete pDict; 366 delete pDict;
367 return nullptr; 367 return nullptr;
368 } 368 }
369 369 if (!key.IsEmpty())
370 if (key.IsEmpty()) 370 pDict->SetFor(key, std::move(pObj));
371 delete pObj;
372 else
373 pDict->SetFor(key, pObj);
374 } 371 }
375 return pDict; 372 return pDict;
376 } 373 }
377 374
378 if (first_char == '[') { 375 if (first_char == '[') {
379 if ((!bAllowNestedArray && dwInArrayLevel) || 376 if ((!bAllowNestedArray && dwInArrayLevel) ||
380 dwInArrayLevel > kMaxNestedArrayLevel) { 377 dwInArrayLevel > kMaxNestedArrayLevel) {
381 return nullptr; 378 return nullptr;
382 } 379 }
383 380
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 614
618 if (buf.GetLength() > kMaxStringLength) 615 if (buf.GetLength() > kMaxStringLength)
619 return CFX_ByteString(buf.GetBuffer(), kMaxStringLength); 616 return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
620 617
621 return buf.MakeString(); 618 return buf.MakeString();
622 } 619 }
623 620
624 bool CPDF_StreamParser::PositionIsInBounds() const { 621 bool CPDF_StreamParser::PositionIsInBounds() const {
625 return m_Pos < m_Size; 622 return m_Pos < m_Size;
626 } 623 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698