summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_parser.cpp
AgeCommit message (Collapse)Author
2017-10-04Fix Heap-use-after-free in CPDF_SecurityHandler::~CPDF_SecurityHandler.Artem Strygin
The CPDF_SecurityHandler contains unowned reference to "ID" array, which is owned by main trailer. Main trailer is owned by CPDF_Parser::m_TrailerData To fix this issue set m_TrailerData before m_pSecurityHandler(CPDF_SecurityHandler) in CPDF_Parser members list. Bug: chromium:771479 Change-Id: I38413ba16b1454ac775c8a07b126fa3b86714c1b Reviewed-on: https://pdfium-review.googlesource.com/15430 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-10-04Unify parsing of cross ref table v4.Artem Strygin
We can use 'Prev' value of first-page cross-reference table trailer for load main cross-reference table, instead of 'T' value of Linearized header (Offset of first entry in main cross-reference table). This is better solution, because this is allow us check entry count in main cross-ref table and unify loading of main cross-ref table with loading methods of non linearized document. See PDF specification: http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf#678 (page 678, Example 3/part 3) Change-Id: I59dcf3c73a0fb561221ded78e827e40535dbd717 Reviewed-on: https://pdfium-review.googlesource.com/13810 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-10-03Simplify CPDF_Parser::GetIDArrayArtem Strygin
Change-Id: Idbd205edcf7400ffc46edf4d9f09be6ace6d0e7f Reviewed-on: https://pdfium-review.googlesource.com/13734 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-10-03Move initialization of CPDF_CryptoHandler into CPDF_SytnaxParser initialization.Artem Strygin
Change-Id: I70d04f38767f2c17c41407fc9b4fc25519ba32f4 Reviewed-on: https://pdfium-review.googlesource.com/15330 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-10-03Move the CryptoHandler into the SecurityHandlerArtem Strygin
Change-Id: Idb5928e65833641d0443d955e4f2866d0f94cf5f Reviewed-on: https://pdfium-review.googlesource.com/15291 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-10-03Remove the parser from the CPDF_SecurityHandler .Artem Strygin
Change-Id: I9fb651285c158e0f61d19e1aaf0d8bcfd302a22f Reviewed-on: https://pdfium-review.googlesource.com/15290 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-10-03Change the ownership of the CPDF_CryptoHandler.Artem Strygin
Change-Id: I3ae8337c1a77063470eb5baa97db62ea2e90688b Reviewed-on: https://pdfium-review.googlesource.com/15230 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-10-02Move CPDF_Parser::ObjectType into protected sectionArtem Strygin
Change-Id: I2a26647359a7d14d7d1269fe2835e0b3184f2ca8 Reviewed-on: https://pdfium-review.googlesource.com/13732 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-10-02Implement CPDF_CryptoHandler::DecryptObjectArtem Strygin
Decryption logic has been extracted from CPDF_SyntaxParser::GetObjectBody into CPDF_CryptoHandler::DecryptObject Performance comparison results: https://pdfium-review.googlesource.com/c/pdfium/+/12970 Change-Id: Iaeaed56b7f96166bbbcf6db162192d2ba9af4698 Reviewed-on: https://pdfium-review.googlesource.com/12971 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-09-28Fix infinite loop on form availability check.Artem Strygin
The problem was, that the CPDF_SyntaxParser read last block not from requested position. In this case It move down requested position to fill whole buffer. As result this additional data was not requested by DownloadHints. To fix this allow resize data buffer in CPDF_SyntaxParser, to store more small block, and always read from requsted position. Also add reading check into CPDF_Parser::LoadLinearizedMainXRefTable to prevent infinite loops. Change-Id: I14d3f4457393025dca390aa3ceaa940716463534 Reviewed-on: https://pdfium-review.googlesource.com/11891 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-09-21Rename CPDF_SyntaxParser::GetObject to GetObjectBodyArtem Strygin
Change-Id: Ia8fd1893f862391fbada396f505ac16985b59cd6 Reviewed-on: https://pdfium-review.googlesource.com/12850 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-09-21Rename CFX_RetainPtr to RetainPtrDan Sinclair
This CL renames CFX_RetainPtr to RetainPtr and places in the fxcrt namespace. Bug: pdfium:898 Change-Id: I8798a9f79cb0840d3f037e8d04937cedd742914e Reviewed-on: https://pdfium-review.googlesource.com/14616 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-09-19Simplify CPDF_Parser::LoadCrossRefV4Artem Strygin
Change-Id: Ie1170e71fb2d8f87857e68620f27e478a0801d21 Reviewed-on: https://pdfium-review.googlesource.com/13670 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-09-18Convert string class namesRyan Harrison
Automated using git grep & sed. Replace StringC classes with StringView classes. Remove the CFX_ prefix and put string classes in fxcrt namespace. Change AsStringC() to AsStringView(). Rename tests from TEST(fxcrt, *String*Foo) to TEST(*String*, Foo). Couple of tests needed to have their names regularlized. BUG=pdfium:894 Change-Id: I7ca038685c8d803795f3ed02545124f7a224c83d Reviewed-on: https://pdfium-review.googlesource.com/14151 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2017-09-05Move Parsing of indirect object logic into CPDF_SyntaxParser.Artem Strygin
Change-Id: I5473d6db3e6fc247d52a83b34424958dc20387f4 Reviewed-on: https://pdfium-review.googlesource.com/12150 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-08-31Disable objects decryption if it is useless.Artem Strygin
Change-Id: I6a588b4af4cfede922bc3756be749e9e30e3e8e5 Reviewed-on: https://pdfium-review.googlesource.com/12370 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-08-31Fix code style.Artem Strygin
rename m_linearized_first_page_cross_ref_start_obj_num --> m_dwLinearizedFirstPageXRefStartObjNum Change-Id: I12194169f10df445d7c81305491775c15c400fad Reviewed-on: https://pdfium-review.googlesource.com/12630 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-08-30Add truly const versions of CPDF_Document getters.Lei Zhang
Instead of only having CPDF_Dictionary* GetRoot() const, provide const CPDF_Dictionary* GetRoot() const and CPDF_Dictionary* GetRoot(). Do the same for GetInfo(). Change-Id: I6eae1208d38327fcdc7d0cd75069a01c95f4a92a Reviewed-on: https://pdfium-review.googlesource.com/11671 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-08-28Unify CPDF_SyntaxParser::GetObjectXXX methods.Artem Strygin
Merge CPDF_SyntaxParser::GetObject and CPDF_SyntaxParser::GetObjectForStrict. Change-Id: Ic9ff51e24ee981c268239847e3cca1c6f6a6f269 Reviewed-on: https://pdfium-review.googlesource.com/10511 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-08-23Simplify Trailers usage in CPDF_Parser.Artem Strygin
Do not store non main trailers in memory. Improve readability. Change-Id: I2eab5d31a5be056871e7e5953e4b38662b91f5ae Reviewed-on: https://pdfium-review.googlesource.com/10750 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-08-21Remove useless code.Artem Strygin
Change-Id: Idd656dcf372c0b8ed515a4e0635b5098c0781d76 Reviewed-on: https://pdfium-review.googlesource.com/10991 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-08-16Fix potential OOM / integer overflow in CPDF_Parser.Lei Zhang
The count passed into ParseAndAppendCrossRefSubsectionData() may be invalid. BUG=chromium:752796 Change-Id: Ic7bbfd16761d1df0855e6c77e4abc68823b12395 Reviewed-on: https://pdfium-review.googlesource.com/11130 Reviewed-by: Art Snake <art-snake@yandex-team.ru> Commit-Queue: Lei Zhang <thestig@chromium.org>
2017-08-09Remove useless code.Artem Strygin
The CPDF_Parser::IsVersionUpdated is not used anymore. Change-Id: I896c42daca3c5bed7b9d700eaea6ced686ab5acb Reviewed-on: https://pdfium-review.googlesource.com/10490 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-08-09Unify initialization of CPDF_Parser.Artem Strygin
Move syntax parser initialization in separate method. Change-Id: I701284b1fee26a474c24ca68948a3462cc68faec Reviewed-on: https://pdfium-review.googlesource.com/10291 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-08-09Unify of saving documents.chromium/3181Artem Strygin
In the original code the method of writing of objects depends on a much unpredictable factors: as: 1) Is there an updated version of the at least one object in the document. 2) The password is changed. 3) Was this object loaded earlier. 4) The Object is compressed and document have a password. With these factors it is difficult to predict what will be the final file. To reduce volatility use only one method that works in all cases mentioned. This method is parse then serialize. Change-Id: I3d7dcadd10abffbad68d1f993f2dd60b039ed989 Reviewed-on: https://pdfium-review.googlesource.com/9572 Commit-Queue: Art Snake <art-snake@yandex-team.ru> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-08-09Unify CPDF_Parser::ParseIndirectObjectAtXXX methods.Artem Strygin
Change-Id: I9ee1da4d0a9751dae8d595b610cf77c074c22cdc Reviewed-on: https://pdfium-review.googlesource.com/10350 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-08-03Avoid a redundant header offset check in CPDF_Parser.Lei Zhang
CPDF_Parser::StartLinearizedParse() calls StartParse(), but already knows the PDF header offset. Refactor StartParse() so it does not have to look for the header again. Change-Id: Id8cc39301ae72da868dafc53921622d5b28ce26e Reviewed-on: https://pdfium-review.googlesource.com/9830 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Art Snake <art-snake@yandex-team.ru>
2017-08-02Unify parsing of cross refs v4Artem Strygin
Change-Id: I7e3d45263a0bae61fd86fd4c3710de7fc0b9347d Reviewed-on: https://pdfium-review.googlesource.com/9290 Reviewed-by: Wei Li <weili@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-08-01Add public access for read stream into CPDF_SyntaxParserArtem Strygin
Change-Id: I5deb6049db41387ac030a6ba5296ee6187120190 Reviewed-on: https://pdfium-review.googlesource.com/9470 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-08-01Improve readability in CPDF_Parser::ObjectInfo.Artem Strygin
Make CPDF_Parser::ObjectInfo::pos a union, since the data is used as an object number when the object is compressed. Change-Id: Id7c32759f7411cc80285bb7f3088b5aa6ff5bf05 Reviewed-on: https://pdfium-review.googlesource.com/9570 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
2017-08-01Change CPDF_Parser::GetIndirectBinary() to return a std::vector.Lei Zhang
Fixes potential leaks in CPDF_Creator::WriteOldIndirectObject(), the only caller. Change-Id: I8a20da8a555c8d28f3bcd467a193a6a81c9f91d9 Reviewed-on: https://pdfium-review.googlesource.com/9751 Reviewed-by: Art Snake <art-snake@yandex-team.ru> Commit-Queue: Lei Zhang <thestig@chromium.org>
2017-07-20Use enum for pdf object typeArtem Strygin
Replace uint8_t type to enum for ObjectType variables Change-Id: Ie33c8c9413c5082397a2c6fbf73e03f08b7d8658 Reviewed-on: https://pdfium-review.googlesource.com/8470 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-06-28Keep all trailers in CPDF_Parser in m_TrailersNicolas Pena
This CL removes m_pTrailer in favor of having them all in a vector, and having an index that points to the position of the previous m_pTrailer in the vector. Bug: pdfium:787 Change-Id: Ieebbf4849f7ea78f8f74d188e3adb3446a53482e Reviewed-on: https://pdfium-review.googlesource.com/7040 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Nicolás Peña <npm@chromium.org>
2017-06-19Fixing metadata not read from linearized file.chromium/3136Henrique Nakashima
This still won't work if the info dict is not on the first page without first calling FPDFAvail_IsFormAvail or FPDFAvail_IsPageAvail, as these are the methods that trigger parsing the rest of the data. Bug: pdfium:664 Change-Id: I0b0193e415a1153dcfb8bfba0e0482da6b6ba53c Reviewed-on: https://pdfium-review.googlesource.com/6610 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
2017-05-26Avoid dangling encrypt dict pointer in CPDF_ParserTom Sepez
CPDF_Parser::StartParse should release the current encrypt dict before trashing it by calling RebuildCrossRef() at cpdf_parser.cpp:195. This gives rise to the pattern that calls to ReleaseEncryptHandler() are followed by SetEncryptDict(nullptr), so just move the later into the former. Bug: 726503 Change-Id: I38bc81f0c0416812035a8a2541c09e875f1fb49a Reviewed-on: https://pdfium-review.googlesource.com/6030 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-05-24Convert to CFX_UnownedPtr, part 3.Tom Sepez
Remove an explicit clear to re-order the member destruction order. Change-Id: I33da3f3de4b8e8e0cfbdceaf5140e98f5d6f904a Reviewed-on: https://pdfium-review.googlesource.com/5791 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-05-16Introduce CFX_UnownedPtr to detect lifetime inversion issues.Tom Sepez
There are places where an object "child" has a raw pointer back to object "owner" with the understanding that owner will always outlive child. Violating this constraint can lead to use after free, but this requires finding two paths: one that frees the objects in the wrong order, and one that uses the object after the free. The purpose of this patch is to detect the constraint violation even when the second path is not hit. We create a template that is used in place of TYPE*. It's dtor, when a memory tool is present, goes out and probes the first byte of the object to which it points. Used in "child", this allows the memory tool to prove that the "owner" is still alive at the time the child is destroyed, and hence the constraint is never violated. Change-Id: I2a6d696d51dda4a79ee2f00a6752965e058a6417 Reviewed-on: https://pdfium-review.googlesource.com/5475 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-05-04Give a couple of char to int functions better names.chromium/3090Lei Zhang
- FXSYS_toDecimalDigit() becomes FXSYS_DecimalCharToInt(). - FXSYS_toHexDigit() becomes FXSYS_HexCharToInt(). Change-Id: If4683e8f85f05124b92ff075056cbc295442087d Reviewed-on: https://pdfium-review.googlesource.com/4930 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2017-05-03CPDF_SyntaxParser::SearchWord() is always backwards and for whole-wordsTom Sepez
Change-Id: Ic31d9cda5e919a754162e14e69cb63671a3fe8b9 Reviewed-on: https://pdfium-review.googlesource.com/4794 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-05-03SetPos to at most the file length to avoid overflowsNicolas Pena
This CL prevents arbitrary position setting which may cause integer overflows. In the bug in question, the PDF says the xrefs are located in a huge position. This then causes problems when calling CPDF_SyntaxParser methods. Bug: chromium:603545 Change-Id: I5f94c38f46a0217e9f12f1bf8b2f3bee3b03cb35 Reviewed-on: https://pdfium-review.googlesource.com/4813 Commit-Queue: Nicolás Peña <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-04-20Convert IFX_MemoryStream to CFX_MemoryStreamDan Sinclair
The CFX_MemoryStream is the only implementation of IFX_MemoryStream. This CL removes the interfaces and uses CFX_MemoryStream directly. Change-Id: I2f43fa39e82dafa7673517d214ae15fd2d0df331 Reviewed-on: https://pdfium-review.googlesource.com/4391 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-04-20Cleanup the fx_extension code.Dan Sinclair
This CL cleans up the fx_extension file. The stream code was moved to fx_stream. IFX_FileAccess was removed and CFX_CRTFileAccess split to its own file. Code shuffled from header to cpp file. Change-Id: I700fdfcc9797cf4e8050cd9ba010ad8854feefbf Reviewed-on: https://pdfium-review.googlesource.com/4371 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-04-13Refcount CPDF_CryptoHandlerchromium/3076chromium/3075chromium/3074chromium/3073chromium/3072Tom Sepez
Avoid tracking ownership via m_bLocalCryptoHandler. Also remove m_bEncryptCloned, as it is always false. Replace some methods with direct calls to underlying code. Change-Id: Ifa9d6f721c59d07e3b8e258f76832ca9f2ea0fc9 Reviewed-on: https://pdfium-review.googlesource.com/4111 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2017-04-04Remove a couple checks for MakeUnique failures.Lei Zhang
Combine some common CCodec_Jbig2Module code. Change-Id: I9a046314bc0e9dddc9a8c1a06b37764e9f3cc4b6 Reviewed-on: https://pdfium-review.googlesource.com/3713 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
2017-04-04RefCount CPDF_StreamAcc all the time.Tom Sepez
Pass stream argument to constructor; it feels like a stream accessor should always be made from a stream rather than passing one in after the fact. Change-Id: Iaa46cb37677b81f0170f5d39bab76ad38ea4af44 Reviewed-on: https://pdfium-review.googlesource.com/3620 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-04-03Drop FXSYS_ from mem methodsDan Sinclair
This Cl drops the FXSYS_ from mem methods which are the same on all platforms. Bug: pdfium:694 Change-Id: I9d5ae905997dbaaec5aa0b2ae4c07358ed9c6236 Reviewed-on: https://pdfium-review.googlesource.com/3613 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-03-14Replace FX_CHAR and FX_WCHAR with underlying types.Dan Sinclair
Change-Id: I96e0a20d66b9184d22f64d8e4ce0dadd5a78c1e8 Reviewed-on: https://pdfium-review.googlesource.com/2967 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-01-10Remove some CFX_ArrayTemplate in fpdfapi and fpdfdoctsepez
Also use unique_ptr in one spot while we're at it. Review-Url: https://codereview.chromium.org/2625483002
2016-12-14Avoid the ptr.reset(new XXX()) anti-patterntsepez
Be suspicious of |new|. This removes some of the easy cases. Review-Url: https://codereview.chromium.org/2571913002
2016-12-07Refcount all the IFX_ stream classes all the time.tsepez
We can remove a lot of "bOwnsStream" logic in the process. Always pass these by const reference, in case the called method wants to hang on to the stream (one exception is where we stick a raw pointer into a void* slot in a context from another layer). Review-Url: https://codereview.chromium.org/2451493002