summaryrefslogtreecommitdiff
path: root/core/fxcodec/jbig2
AgeCommit message (Collapse)Author
2018-08-22Use UnownedPtr<> in JBig2_TrdProc, part 2.Tom Sepez
Re-order some locals to obey strict lifetime constraint. Pack a little tighter. Change-Id: Iae011d21b934fac865cf10ac20c046c8917d3a98 Reviewed-on: https://pdfium-review.googlesource.com/40915 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-21Use UnownedPtr<> in JBIG2_SDDProc.Tom Sepez
Pack a little tighter while at it. Change-Id: If7cbb324ebf828a4bb60eb364fc3e0f31625e57f Reviewed-on: https://pdfium-review.googlesource.com/40913 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-21Use UnownedPtr<> in JBig2_GrrdProc.h.Tom Sepez
Change-Id: Ie3502443b801ae4af6e4c9e533f28d102703104c Reviewed-on: https://pdfium-review.googlesource.com/40912 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-21Use UnownedPtr<> in CJBig2_TRDProc.Tom Sepez
First real use case of assigning Unowned to MaybeOwned. Change-Id: Ia5bc7102012f7a09120ba02d38cf751547d5c005 Reviewed-on: https://pdfium-review.googlesource.com/40914 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-21Avoid copying some big vectors in JBIG2_SymbolDictTom Sepez
Change-Id: I662f65b53a1a17be0062c92452d82acbbe157477 Reviewed-on: https://pdfium-review.googlesource.com/40910 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-21Fix lifetime issue in CJBig2_GRDProc::ProgressiveArithDecodeStateTom Sepez
Bug: 876222 Change-Id: I56c20c006ee26650f32b9ec90f3c7f91466b7470 Reviewed-on: https://pdfium-review.googlesource.com/40890 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-20Use UnownedPtr<> in JBig2_GrdProc.hTom Sepez
Pack a little tighter while we're at it. Change-Id: I8cbefe5df1b4340cb55ea14a5ae00ebc1ad07114 Reviewed-on: https://pdfium-review.googlesource.com/40774 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-10Fix a JBIG2 decoding regression.Lei Zhang
When trying to sanity check SBNUMINSTANCES for JBIG2 text regions for https://crbug.com/837192, the check did not take data encoding into account. Fix this by assuming there is a potential for 16:1 compression in the lossless encoding. BUG=chromium:871848 Change-Id: I991dacff9fbefa4e302f5ce92a355902ef94308a Reviewed-on: https://pdfium-review.googlesource.com/39790 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-08-07Combine redundant CJBig2_Image code.Tom Sepez
Once upon a time, someone cut-n-pasted ~300 lines of code to avoid creating a default rectangle and to save a couple of additions. Then one path got one set of fixes (safe ints) and the other path got a second set of fixes (source bounds checks). Re-unify, picking up all the fixes, since they are identical otherwise. Change-Id: I099e854bc8ad027efabd5c2077c4319ee8221256 Reviewed-on: https://pdfium-review.googlesource.com/39550 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-06Small optimization in CJBig2_Image::SubImage()Tom Sepez
We can use the memcpy() path whenever byte aligned. Split code into helper methods. Add test for fast path specifically. Change-Id: I52f6129b0e788eb2da60536cfa6fce12a0609375 Reviewed-on: https://pdfium-review.googlesource.com/39432 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-02Use more helper macros/methods in JBig2_Image.cpp.Tom Sepez
Bundling the test with the accessor is a safer pattern than performing the check externally. Add test for CopyLine(). Change-Id: I7056bf33bdca40cb84a89e4928567a389d88ff1c Reviewed-on: https://pdfium-review.googlesource.com/39431 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-02Tidy JBig2_Image.cppchromium/3511Tom Sepez
Add checked/unchecked GetLine(y) methods and use them. Introduce BIT_INDEX_TO_ALIGNED_BYTE() to de-mystify some shifting. Move local declarations to spot of use. Remove spurious Fill(), as we initialize to 0s. Initialize members in header where possible. Add unit tests. Change-Id: I41ccb91b57320dbc790fd0f680f6d98571280343 Reviewed-on: https://pdfium-review.googlesource.com/39370 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-08-02Introduce JBIG2_PUTDWORD() macro in CJBIG2_Image.hTom Sepez
Provide symmetry with JBIG2_GETDWORD(). Avoid potential illegal undefined signed shift in JBIG2_GETDWORD(). Get better column alignment under cl-format via pointless shift by zeros for consistency. Change-Id: I13d46fe7976074e26df72b58a055788390191364 Reviewed-on: https://pdfium-review.googlesource.com/39430 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-01Bounds check lineSrc in JBig2_Image.cpp.Tom Sepez
No matter how the dimensions might be determined, we know the hard end of the source line, and can use it for a bounds check. We expect the size is quantized to a multiple of m_stride, so as long as each block operates within an m_stride, the initial check should be sufficient. Bug: 867501 Change-Id: Iaf9936557b856f3eb09fef522f3e6738aa4f38f0 Reviewed-on: https://pdfium-review.googlesource.com/39310 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-27Merge several methods into JBig2GrdProc::DecodeArithTemplateUnoptchromium/3505Nicolas Pena
This CL merges DecodeArithTemplateXUnopt for X=0,1,2. This is similar to how three methods were merged into DecodeArithOpt3. Change-Id: Ib0d4f14de6a8c924517d82eaec7577961503a325 Reviewed-on: https://pdfium-review.googlesource.com/38935 Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2018-07-06Fix regression in CJBig2_TRDProc.chromium/3486chromium/3485chromium/3484Lei Zhang
Commit 7695dd0f mistakenly changed a signed integer to unsigned. This is incorrect because right shifts for negative integers behave differently. BUG=chromium:859284 Change-Id: Id9c54848b15ace1de080c174f261dd2c064018e0 Reviewed-on: https://pdfium-review.googlesource.com/37230 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-07-02Check for more integer overflows in CJBig2_TRDProc.Lei Zhang
BUG=chromium:859284 Change-Id: I41ce5de4cca0a863dc6e60b64fd69d36c2672a64 Reviewed-on: https://pdfium-review.googlesource.com/36790 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-06-29Limit image size in CJBig2_PDDProc.Lei Zhang
CJBig2_PDDProc internally creates a CJBig2_GRDProc to create an image. If the image is too big, then processing it can use up too much memory. BUG=chromium:857106 Change-Id: I06a9eaed6941be1cbb7481d21048e6a1681696b7 Reviewed-on: https://pdfium-review.googlesource.com/36490 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-06-29Clean up CJBig2_PDDProc.Lei Zhang
Change-Id: Ia83ac5dae0dedf55f1b0f0cf2a728c64474f72db Reviewed-on: https://pdfium-review.googlesource.com/36450 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-06-14Merge 3 methods of CJBig2_GRDProc togetherchromium/3465chromium/3464chromium/3463chromium/3462chromium/3461Nicolas Pena
This CL merges 3 methods into a single DecodeArithOpt3(). The code is the same, except for some constants which are extracted out as namespace variables. Change-Id: I6d9127d71b5e7c4c75e31a736b0f3307bb78a076 Reviewed-on: https://pdfium-review.googlesource.com/35170 Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-06-13Make CJBig2_Context::GetHuffmanTable return constNicolas Pena
This CL changes GetHuffmanTable() to return a const pointer and fixes other members / functions accordingly. Change-Id: Ie62fe044b3156f67885dd4fa1f6512cbd35a83d3 Reviewed-on: https://pdfium-review.googlesource.com/35116 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
2018-05-24Do some variable cleanup in CJBig2_ContextNicolas Pena
This CL cleans up variables in CJBig2_Context. It moves some declarations further, to when the variables are actually used. It also caches huffman tables in a vector of unique_ptr. Change-Id: Id3af96f9526b1000f681e4e2b174bba07b45ee55 Reviewed-on: https://pdfium-review.googlesource.com/32715 Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-05-22Remove JBIG2_memcpy() and JBIG2_memset().Lei Zhang
Just use memcpy() and memset(). Change-Id: Id6c6fab4e65a5524786ae318270c5981313825f2 Reviewed-on: https://pdfium-review.googlesource.com/32743 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2018-05-22Remove return value from CJBig2_Image::SetPixel().Lei Zhang
Nobody reads it. Change-Id: I76c0f5881e5432d2086cb8eaec7fc70fa5b71536 Reviewed-on: https://pdfium-review.googlesource.com/32741 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2018-05-22Fix method style in JBig2_Image.Lei Zhang
Rename fooBar() to FooBar(). Change-Id: I87775fa14ce7e4f4a5897780d0d02fb61c7693ff Reviewed-on: https://pdfium-review.googlesource.com/32739 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-05-17Expose CJBig2_Image::ComposeTo() as a public method.Lei Zhang
CJBig2_Image::ComposeFrom() wraps a call to ComposeTo() and does an extra validity check. In tight loops where the validity check will always succeed, this is wasteful. Change existing callers of ComposeFrom() to ComposeTo() when the validity check has already been done. BUG=chromium:840728 Change-Id: I39fb42eea49b92b7804cbd42c3d8a0329edeb58d Reviewed-on: https://pdfium-review.googlesource.com/32637 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-05-17Consolidate identical code in CJBig2_TRDProc.Lei Zhang
Change-Id: Ib44a6b7bd19625a4081322d2471551bec894abd8 Reviewed-on: https://pdfium-review.googlesource.com/32638 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-05-16Move JBig2 HuffmanTables into JBig2_HuffmanTable.cppNicolas Pena
This CL changes the table information so it can be indexed, and allows moving all of the information to the CJBig2_HuffmanTable implementation, which is the only real user of the data. Change-Id: I88780bee32c8509198518fd3b1e82d68ae7ff707 Reviewed-on: https://pdfium-review.googlesource.com/32635 Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-05-14Merge some values of JBig2_ResultNicolas Pena
This CL merges some of the values of JBig2_Result. The only checks are against Success and EndOfFile || EndOfPage, so we only need three values: Success, EndReached, and Failure (for anything that does not match either of those two). Change-Id: I552c54f2d70aa8e8bf52702dab4dfc00d528ef76 Reviewed-on: https://pdfium-review.googlesource.com/32393 Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-05-10Remove a completeness check from CJBig2_GRRDProc::DecodeTemplate0OptNicolas Pena
https://pdfium-review.googlesource.com/c/pdfium/+/18333 introduced several checks to prevent timeouts in JBig2. One of these is breaking the PDF in the bug, so this CL removes that check. Bug: chromium:841200 Change-Id: Ia75c699b7fddc26f0353b0d64349898c4d1f744d Reviewed-on: https://pdfium-review.googlesource.com/32250 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
2018-05-09Use enum class instead of int in CJBig2_Contextchromium/3426Nicolas Pena
This CL changes CJBig2_Context return methods as follows: * Internal methods return JBig2_Result instead of int. * Public methods return a bool (for success/failure) instead of int. In a followup, several of the enum class values may be merged together since they are not all needed. Change-Id: Ifdab83b8037262370cd7c4a80e94aa94d59aa589 Reviewed-on: https://pdfium-review.googlesource.com/32310 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
2018-05-09Make memory usage in CJBig2_HTRDProc::DecodeImage() O(1).Lei Zhang
Instead of allocating an N-pixel array to store some temporary values, just use a single integer. BUG=chromium:840728 Change-Id: I7a0ff83d814eff127033f25020a7c398db3c2062 Reviewed-on: https://pdfium-review.googlesource.com/32290 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-05-04Check CJBig2_Image is valid before filling.chromium/3423chromium/3422chromium/3421Lei Zhang
Skip a lot of work that will all fail anyway. BUG=chromium:838347 Change-Id: Iba45120e436b5547e106feb27dadea92cc948258 Reviewed-on: https://pdfium-review.googlesource.com/32053 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-05-02Make several Huffman decoders consistently check for integer overflows.Lei Zhang
BUG=chromium:837972 Change-Id: I6cfa28bff38870419e4b1e2bced427cfcbf843cd Reviewed-on: https://pdfium-review.googlesource.com/31912 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-05-01Add struct CJBig2_GRDProc::ProgressiveArithDecodeState.Lei Zhang
Track the decode state in one data structure. Also grab pointers to data structure members before tight loops when decoding. It turns out referring to this->foo in tight loops can actually slow down decoding. Change-Id: I6a09b08ca06ef05968966055b5ad20f8c89896af Reviewed-on: https://pdfium-review.googlesource.com/31790 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-05-01Clean up CJBig2_Image compose methods.Lei Zhang
- Mark them private when possible. - Disambiguate method names. - Make method names match the style guide. - Pass in rects by reference. Change-Id: I0bf848756e81a92d20e46a81cd6260b660eaf482 Reviewed-on: https://pdfium-review.googlesource.com/31772 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-04-27Remove CJBig2_HuffmanTable::InitCodes().Lei Zhang
Use CJBig2_Context::HuffmanAssignCode() instead. Change-Id: Ief187420494a8cefa26eeedb98a55683caf7807b Reviewed-on: https://pdfium-review.googlesource.com/31538 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-04-27Change CJBig2_HuffmanTable to use struct JBig2HuffmanCode.Lei Zhang
Change-Id: I6461f81a3d8005efa75b8141c18c502a63252883 Reviewed-on: https://pdfium-review.googlesource.com/31537 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-04-27Adjust CJBig2_Context::HuffmanAssignCode().Lei Zhang
It looks a lot like CJBig2_HuffmanTable::InitCodes(). Port over the UBSAN error fix from commit 76c9a1b1. BUG=chromium:709781 Change-Id: I5d2f8fb013c09099c82b0565627b77e4fb0f8a98 Reviewed-on: https://pdfium-review.googlesource.com/31536 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-04-27Simplify CJBig2_Context::DecodeSymbolIDHuffmanTable().Lei Zhang
One of its parameters is a member variable. Change-Id: I0dcb78275d9ea5b05a77e211d178a0efb8699395 Reviewed-on: https://pdfium-review.googlesource.com/31535 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-04-27Use std::function in CJBig2_GRDProc.Lei Zhang
Pick from a set of functions before calling it, instead of having code to call all of the functions with the same parameters. Change-Id: I7f479948f50bdc1a9eb2764d5eb7505dc7434418 Reviewed-on: https://pdfium-review.googlesource.com/31533 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-04-27Disambiguate methods in CJBig2_GRDProc.Lei Zhang
Also remove method parameters that always refer to the same member variables. Change-Id: I9751d63895cc59e5280283795e39b50fd42eef94 Reviewed-on: https://pdfium-review.googlesource.com/31532 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2018-04-27Simplify CJBig2_Context::FindReferredSegmentByTypeAndIndex().Lei Zhang
It only looks for a single segment type. Change-Id: I83457c6f74c210299caec79a563e7876f4d1d9ea Reviewed-on: https://pdfium-review.googlesource.com/31534 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-04-27Fix style for many jbig2 methods.chromium/3412Lei Zhang
Change-Id: Ie700e132f13f2cb4851ea59b68c891e3c42af243 Reviewed-on: https://pdfium-review.googlesource.com/31531 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-04-27Add CJBig2_Image::IsValidImageSize() helper method.Lei Zhang
Change-Id: Ic2acd6f03b9b2e52b3d94d7579d5dc36c8e62c96 Reviewed-on: https://pdfium-review.googlesource.com/31530 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-04-27Sanitize another image size in CJBig2_Context::parseHalftoneRegion().Lei Zhang
BUG=chromium:836872 Change-Id: I0362fd7708043648bffa26c9248b401ea2793a21 Reviewed-on: https://pdfium-review.googlesource.com/31510 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-04-27Sanitize the SBNUMINSTANCES value in the JBIG2 decoder.Lei Zhang
BUG=chromium:837192 Change-Id: Ib9c0e7b4aeb6501e81308844d344a784f7c138d8 Reviewed-on: https://pdfium-review.googlesource.com/31490 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-04-23Add more image size checks in CJBig2_Context.Lei Zhang
BUG=chromium:834557 Change-Id: I8fb8d74f87097b39608c3f83f2fa1c4e49e69980 Reviewed-on: https://pdfium-review.googlesource.com/31170 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-03-06Rename core/fxcrt IFX files to IfaceDan Sinclair
This CL renames the 3 IFX files in core/fxcrt to Iface instead. Change-Id: I7cee6836650b71bc5c5729a8147fda62f0910fe3 Reviewed-on: https://pdfium-review.googlesource.com/27970 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2018-02-26Shrink some tables and kill dead code in xfa.Tom Sepez
Change-Id: Ic1260417e7d1475dd518655b2ab08f0184955d88 Reviewed-on: https://pdfium-review.googlesource.com/27170 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>