pdfium.git
4 years agoSimplify PDFium by removing code that's not used in the open source repo.
John Abd-El-Malek [Sat, 13 Dec 2014 00:42:18 +0000]
Simplify PDFium by removing code that's not used in the open source repo.

-remove parameter from FPDF_InitLibrary
-remove a bunch of ifdefs that are unused

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/801913002

4 years agom_pColorSpace can not be NULL for image object with DCTDecode filter
Bo Xu [Thu, 11 Dec 2014 22:24:35 +0000]
m_pColorSpace can not be NULL for image object with DCTDecode filter

BUG=411842
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/792113003

4 years agoDo not do strict check of BitsPerComponent for RunLengthDecode filter
Bo Xu [Thu, 11 Dec 2014 00:45:46 +0000]
Do not do strict check of BitsPerComponent for RunLengthDecode filter

BUG=438421
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/790363002

4 years agoLab colorspace needs to be 3 component
Bo Xu [Thu, 11 Dec 2014 00:00:29 +0000]
Lab colorspace needs to be 3 component

BUG=429134
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/791223002

4 years agoTrailer should be a dictionary object
Bo Xu [Tue, 9 Dec 2014 18:13:59 +0000]
Trailer should be a dictionary object

BUG=https://code.google.com/p/pdfium/issues/detail?id=86

a "<<" token should follow "trailer" but "<" will trick the parser to make trailer a hex string object.

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/787753002

4 years agoReplace manual/error-prone/hard-to-verify arraysize calculations with safe FX_ArraySi...
Bruce Dawson [Tue, 9 Dec 2014 00:19:45 +0000]
Replace manual/error-prone/hard-to-verify arraysize calculations with safe FX_ArraySize macro.

pdfium has numerous places where the number of elements in an array is
calculated with expressions like:

    sizeof(cFormats)/sizeof(FX_LPCWSTR)

This is suboptimal because it is verbose, it is easy to get wrong, and
it cannot be determined through casual inspection whether the code is
correct. It will give incorrect results if cFormats is a pointer instead
of an array and it will give incorrect results if FX_LPCWSTR is not the
type of the array elements.

The FX_WSTRC macro in fx_string.h which I fixed was particularly scary
because it would silently misbehave if passed a pointer.

The FX_ArraySize macro which I have added and started using (taken from
arraysize in v8's macros.h) is easier to use and will always give correct
results. If passed a pointer it will fail to compile.

For this change I only fixed instances of sizeof(FX_LPCWSTR). There
appear to be about 150 other places in the pdfium code that could
benefit from using FX_ArraySize.

R=bo_xu@foxitsoftware.com, tsepez@chromium.org

Review URL: https://codereview.chromium.org/729293003

4 years agoGetting rid of more (FX_LPCWSTR) casts and fixing two bugs revealed by this.
Bruce Dawson [Mon, 8 Dec 2014 21:10:02 +0000]
Getting rid of more (FX_LPCWSTR) casts and fixing two bugs revealed by this.

Since casts to FX_LPCWSTR have been shown to hide bugs I tried removing
more of them, targeting those places where a cast was used to force a
conversion from CFX_WideString to FX_LPCWSTR, replacing these casts with
calls to the newly added .c_str() function. This revealed two places
where the cast was hiding a bug -- where ->c_str() was required instead!

This removes ~33 FX_LPCWSTR casts and there are ~31 left, many of which
will go away in some future change.

Also includes this change:

Removing unnecessary casts from wchar_t* to wchar_t*, by various names.

Original patch from Bruce Dawson(brucedawson@chromium.org)

R=bo_xu@foxitsoftware.com, tsepez@chromium.org

Review URL: https://codereview.chromium.org/733693003

4 years agoCleanup: Remove an unused function.
Lei Zhang [Thu, 4 Dec 2014 02:22:40 +0000]
Cleanup: Remove an unused function.

R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/775903002

4 years agoAdd a missing 'using' keyword in big integer library
Bo Xu [Wed, 3 Dec 2014 00:48:41 +0000]
Add a missing 'using' keyword in big integer library

Review URL: https://codereview.chromium.org/770673004

4 years agoModify big integer library
Bo Xu [Wed, 3 Dec 2014 00:34:20 +0000]
Modify big integer library

This patch follows https://pdfium.googlesource.com/pdfium/+/44047c3300d07192a67b1714084cc2d43b1e9bd9

Modify the library to resolve compile error,
add copyright notice and change pdfium.gyp and BUILD.gn

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/754743003

4 years agoRemove unnecessary files in third_party/bigint
Bo Xu [Tue, 2 Dec 2014 22:28:36 +0000]
Remove unnecessary files in third_party/bigint

This patch follows the initial check in of big integer library at
https://pdfium.googlesource.com/pdfium/+/7504b3d87d6143661746d85c3c3e4052939b4e52

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/773923002

4 years agoInitial check in of big integer library, v2010.04.30
Bo Xu [Tue, 2 Dec 2014 21:06:22 +0000]
Initial check in of big integer library, v2010.04.30

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/773443004

4 years agoUpdate to openjpeg r2944
Bo Xu [Mon, 24 Nov 2014 21:58:10 +0000]
Update to openjpeg r2944

BUG=429139,430566,431288
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/758593002

4 years agoFix blank page issues caused by too strict check
Jun Fang [Thu, 20 Nov 2014 02:58:01 +0000]
Fix blank page issues caused by too strict check

Before this fix, PDF parser aborts the parsering process when detecting an error.
For this case, PDF parser just gives up parsering when it detects that the length of
image stream is incorrect. The solution to this case is to find the tag "endstream"
and "endobj" to calculate the length rather than aborting the parsering process.

BUG=433339
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/743263002

4 years agoFixed crash on NULL de-referencing.
Vitaly Buka [Wed, 19 Nov 2014 01:17:31 +0000]
Fixed crash on NULL de-referencing.

BUG=433992
R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/733273002

4 years agoFixing operator so that bCheckRight isn't always true. Unknown effect!
Bruce Dawson [Tue, 18 Nov 2014 21:50:28 +0000]
Fixing operator so that bCheckRight isn't always true. Unknown effect!

VC++'s /analyze points out that this expression:
    FX_BOOL bCheckRight = type != 'D' || type != 'W';"
is always true. This means that the tests for the right edge of a word

Original patch from Bruce Dawson(brucedawson@chromium.org)

BUG=427616
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/731673003

4 years agoFixing format strings to remove 'z' size specifier.
Bruce Dawson [Tue, 18 Nov 2014 17:55:38 +0000]
Fixing format strings to remove 'z' size specifier.

As of the 2013 version VC++ still doesn't support the 'z' size specifier. This makes portable printing of size_t types frustrating. The simplest general solution is to use %u and cast to unsigned. If there was any possibility of the numbers getting larger than 32-bit then we would need better alternatives, but there is not.

This was found through code inspection, through /analyze, and through pdfium_test print this non-helpful message:

Loaded, parsed and rendered zu pages.
Skipped zu bad pages.

I can confirm that the fix works on Windows and it should work identically on mac. This is a follow-on to change 02e6ca4c4f.

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/738433003

4 years agoRemoving unnecessary casts from wchar_t* to wchar_t*, by various names.
Bruce Dawson [Mon, 17 Nov 2014 23:33:04 +0000]
Removing unnecessary casts from wchar_t* to wchar_t*, by various names.

Remove casts that merely cast from wchar_t* to wchar_t*. Sometimes the
types or casts are FX_LPCWSTR but the idea is the same. Excess casts
can (and have) hidden bugs so removing these may prevent future problems.

Original patch from Bruce Dawson(brucedawson@chromium.org)

R=bo_xu@foxitsoftware.com, tsepez@chromium.org

Review URL: https://codereview.chromium.org/730993002

4 years agoZero initialize ch to avoid possible bug - conditions are very subtle.
Bruce Dawson [Mon, 17 Nov 2014 23:22:03 +0000]
Zero initialize ch to avoid possible bug - conditions are very subtle.

Whether ch and iRet are read without being initialized depends on complex
preconditions and cannot be determined by looking at these function.
Therefore it seems prudent to zero initialize them to avoid any risk.

BUG=427616
R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/727083002

4 years agoAdd Bruce to AUTHORS
Bo Xu [Mon, 17 Nov 2014 22:33:34 +0000]
Add Bruce to AUTHORS

R=jam@chromium.org

Review URL: https://codereview.chromium.org/727403003

4 years agoRename functions in test code also -- fixing build-break from 2c021e0
Bo Xu [Mon, 17 Nov 2014 00:46:31 +0000]
Rename functions in test code also -- fixing build-break from 2c021e0

Change 2c021e0 fixed spelling errors in a couple of functions, but didn't
update the test code leading to two compilation errors. Fixed in this
change.

Original patch from Bruce Dawson(brucedawson@chromium.org)

R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/727243002

4 years agoCorrect typo in form fill environment functions
Bo Xu [Sat, 15 Nov 2014 01:40:50 +0000]
Correct typo in form fill environment functions

Complementary patch in chromium is in https://codereview.chromium.org/711553003

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/700373006

4 years agoRemove FX_LPCWSTR cast to wchar_t* literals
Bo Xu [Sat, 15 Nov 2014 01:03:50 +0000]
Remove FX_LPCWSTR cast to wchar_t* literals

BUG=https://code.google.com/p/pdfium/issues/detail?id=78
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/726143002

4 years agoChange from 'this' to L'this' and remove the cast that was hiding this mismatch.
Bo Xu [Fri, 14 Nov 2014 22:18:05 +0000]
Change from 'this' to L'this' and remove the cast that was hiding this mismatch.

Found by VC++'s /analyze. Warning was:

fpdfsdk\src\javascript\js_runtime.cpp(352) : warning C6276:
Cast between semantically different string types:  char * to wchar_t *.
Use of invalid string can lead to undefined behavior.

This mismatch has been there as far back as the history goes (to May of this year).

It looks like a real bug to me. However I don't know the implications of this bug and why it would not have been noticed at run-time.

The code has been this way as far back as the git history goes, but that is only to May 2014.

Original patch from Bruce Dawson(brucedawson@chromium.org)

BUG=427616
R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/705503004

4 years agoFix build warning on android under stricter compilation rules.
Tom Sepez [Fri, 14 Nov 2014 19:29:28 +0000]
Fix build warning on android under stricter compilation rules.

Error is "converting to non-pointer type 'FX_DWORD'".
TBR=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/726033002

4 years agoBuild pdfium_test executable under GN.
Tom Sepez [Fri, 14 Nov 2014 00:59:03 +0000]
Build pdfium_test executable under GN.

This is the first side of a two-sided patch;
the dependency on //third_party/pdfium/samples will be included from //pdf/BUILD.gn in the chrome repo.

BUG=https://code.google.com/p/pdfium/issues/detail?id=77
R=dpranke@chromium.org

Review URL: https://codereview.chromium.org/720193004

4 years agoMake DEPS use relative paths to fix recipe
Aneesh Mulye [Thu, 13 Nov 2014 21:59:20 +0000]
Make DEPS use relative paths to fix recipe

Context: DEPS was originally added to pdfium to allow its recipe to
automatically check out its dependencies. The recipe used absolute
paths, and so the checkout directory's name ('pdfium') had to be
prefixed to the directory checkout of every dependency, as gclient in
the recipe worked one level above the pdfium checkout itself.

After change fe4537269fc7133320a5131638757f2ffa6bd854, the recipe no
longer worked. To fix this, I'm making DEPS use relative paths.

BUG=375773
R=jam@chromium.org

Review URL: https://codereview.chromium.org/724113003

4 years agoFix a bug when performing StretchDIBits on bit mask
Bo Xu [Mon, 10 Nov 2014 21:34:05 +0000]
Fix a bug when performing StretchDIBits on bit mask

BUG=401988
R=vitalybuka@chromium.org

Review URL: https://codereview.chromium.org/618073003

4 years agoFix bug with reading from uninitialized variable found by VC++'s /analyze.
Tom Sepez [Thu, 6 Nov 2014 23:00:36 +0000]
Fix bug with reading from uninitialized variable found by VC++'s /analyze.

The flag variable is conditionally initialized but unconditionally read.

Warning was:
src\fpdfapi\fpdf_page\fpdf_page_pattern.cpp(274) : warning C6001:
Using uninitialized memory 'flag'.

BUG=427616
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/703213004

4 years agoAdding constructor to _FX_SYSTEMTIME to resolve uninitialized read bugs found by...
Tom Sepez [Thu, 6 Nov 2014 22:38:12 +0000]
Adding constructor to _FX_SYSTEMTIME to resolve uninitialized read bugs found by /analyze on some error paths

Warning from /analyze was:
src\third_party\pdfium\fpdfsdk\include\fsdk_mgr.h(96) : warning C6001: Using uninitialized memory 'fxtime'.

Other error paths can also lead to reading from an uninitialized _FX_SYSTEMTIME object.

Code-gen for the constructor is small enough (four writes of zeroed EAX with VC++, less with gcc) to make putting the constructor in a .cc file unnecessary.

Approval of in-class member initialization would make this fix simpler but that has not quite been approved yet.

BUG=https://code.google.com/p/pdfium/issues/detail?id=70
BUG=427616
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/692533005

4 years agoFix PDFium build with Windows GN.
John Abd-El-Malek [Thu, 6 Nov 2014 18:42:39 +0000]
Fix PDFium build with Windows GN.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/695183005

4 years agoUndo an old change in freetype to account for size of USHORT
Bo Xu [Thu, 30 Oct 2014 23:02:56 +0000]
Undo an old change in freetype to account for size of USHORT

BUG=418582
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/680833006

4 years agoFor v8 Global Object, do not copy in CJS_Value constructor.
Tom Sepez [Thu, 30 Oct 2014 20:23:42 +0000]
For v8 Global Object, do not copy in CJS_Value constructor.

BUG=425129
R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/688303003

4 years agoUpdate openjpeg to r2920
Bo Xu [Thu, 30 Oct 2014 20:10:50 +0000]
Update openjpeg to r2920

BUG=414036, 425151
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/688633003

4 years agoResolve compilation error with G++ 4.9.
Tom Sepez [Wed, 29 Oct 2014 22:31:20 +0000]
Resolve compilation error with G++ 4.9.

Add a check for zero-length keys to avoid hitting the equivalent of |""[1]|.
BUG=https://code.google.com/p/pdfium/issues/detail?id=58
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/665223003

4 years agoupdate openjpeg to r2911
Bo Xu [Wed, 22 Oct 2014 22:32:43 +0000]
update openjpeg to r2911

BUG=418976, 425150, 414525
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/671943002

4 years agoChange the clear order of pDocPage and pDocRender
Bo Xu [Tue, 21 Oct 2014 21:50:16 +0000]
Change the clear order of pDocPage and pDocRender

pTransfer function is released in pDocRender cleanup but is still being accessed in
~CPDF_GeneralStateData in pDocPage cleanup.

BUG=419320
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/662063003

4 years agoUpdate openjpeg to r2908
Bo Xu [Tue, 21 Oct 2014 20:05:17 +0000]
Update openjpeg to r2908

BUG=414089, 414310, 414606
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/670813002

4 years agoMore fixes in sycc422_to_rgb and sycc420_to_rgb when image width is odd
Bo Xu [Tue, 21 Oct 2014 19:17:39 +0000]
More fixes in sycc422_to_rgb and sycc420_to_rgb when image width is odd

This patch is supplementary to issue 418881

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/645793007

4 years agoAdd missing parenthesis in FXARGB_GETDIB macro
Bo Xu [Tue, 21 Oct 2014 19:04:41 +0000]
Add missing parenthesis in FXARGB_GETDIB macro

You can get warning when using FXARGB_GETDIB() with & operation in
the same statement like: FXARGB_GETDIB(src_scan) & 0xffffff in
fx_dib_composite.cpp:

../../third_party/pdfium/core/src/fxge/dib/fx_dib_composite.cpp:737:205:
error: '&' within '|' [-Werror,-Wbitwise-op-parentheses]

Original patch from jiangj@opera.com

R=thakis@chromium.org

Review URL: https://codereview.chromium.org/578253002

4 years agoMake DEPS not add an extra pdfium directory.
John Abd-El-Malek [Thu, 16 Oct 2014 22:32:26 +0000]
Make DEPS not add an extra pdfium directory.

This makes gclient config and gclient sync work.

BUG=423896
TBR=aneeshm@chromium.org

Review URL: https://codereview.chromium.org/656353002

4 years agoFix standalone build on Linux and Mac.
John Abd-El-Malek [Thu, 16 Oct 2014 21:26:18 +0000]
Fix standalone build on Linux and Mac.

BUG=423883
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/663633002

4 years agoFix licenses in headers to pass Chromium's checklicenses tool.
Tom Sepez [Wed, 15 Oct 2014 17:16:45 +0000]
Fix licenses in headers to pass Chromium's checklicenses tool.

This is a re-landing of the changes in https://pdfium.googlesource.com/pdfium/+/6387aff
which were lost during a libopenjpeg library roll.

TBR=thestig@chromium.org

Review URL: https://codereview.chromium.org/661463003

4 years agoStore the address of the page data map's value for proper referencing.
Bo Xu [Wed, 15 Oct 2014 00:10:06 +0000]
Store the address of the page data map's value for proper referencing.

CPDF_Pattern objects are counted and maintained in m_PatternedMap.
When a CPDF_Pattern object "pattern" is deleted, it's address is marked as NULL in m_PatternMap.
This patch stores the address of CPDF_Pattern's adderss in all objects that references "pattern",
to ensure valid referencing after deletion.

BUG=416319, 419976, 418392
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/656753002

4 years agoDon't leave dangling pointer to out-of-scope local in CPDF_StreamContentParser::Parse.
Tom Sepez [Tue, 14 Oct 2014 21:40:57 +0000]
Don't leave dangling pointer to out-of-scope local in CPDF_StreamContentParser::Parse.

This is just a bit of defensive programming; I'm not sure the situation can
occur in the current code, but the following code is likely to set off a red
flag to anyone who reads it:
    CPDF_StreamParser syntax(pData, dwSize);
    m_pSyntax = &syntax;
since the extent of the local |syntax| is far less than the pointer member
|m_pSyntax|.  NULL it out before syntax goes out of scope.

R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/652063002

4 years agoGlyph index is out of range in cff_get_glyph_name.
Jun Fang [Tue, 14 Oct 2014 20:57:19 +0000]
Glyph index is out of range in cff_get_glyph_name.
Glyph index shall be less than number of glyphs.

BUG=418585
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/652363002

4 years agoFix off-by-one in sizing of m_EmbeddedToUnicodes.
Tom Sepez [Mon, 13 Oct 2014 20:16:32 +0000]
Fix off-by-one in sizing of m_EmbeddedToUnicodes.

BUG=421196
R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/656463006

4 years agoFix a bug when image width is odd in sycc422_to_rgb
Bo Xu [Fri, 10 Oct 2014 22:57:36 +0000]
Fix a bug when image width is odd in sycc422_to_rgb

BUG=418881
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/648823002

4 years agoEnable C linkage in fpdfppo.h
Bo Xu [Fri, 3 Oct 2014 20:18:55 +0000]
Enable C linkage in fpdfppo.h

BUG=pdfium-52
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/623893003

4 years agocheck pointer overflow in t2.c
Bo Xu [Fri, 3 Oct 2014 19:29:54 +0000]
check pointer overflow in t2.c

BUG=413375
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/624023003

4 years agoAdd openjpeg pre-processor OPJ_STATIC to pdfium.gyp
Bo Xu [Fri, 3 Oct 2014 18:06:35 +0000]
Add openjpeg pre-processor OPJ_STATIC to pdfium.gyp

Openjpeg removed the definition of OPJ_STATIC in openjpeg.h.
This change is merged in https://pdfium.googlesource.com/pdfium/+/d53e6fdb0a86ca1ddb12876a60f7f2d7508b5349
So need to add OPJ_STATIC to pdfium.gyp

BUG=None
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/624043002

4 years agoUpdate openjpeg
Bo Xu [Tue, 30 Sep 2014 18:12:05 +0000]
Update openjpeg

BUG=407964, 414182, 413447
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/589243004

4 years agoUse static_assert unconditionally.
Peter Kasting [Sat, 27 Sep 2014 01:09:20 +0000]
Use static_assert unconditionally.

BUG=none
TEST=none
R=jam@chromium.org

Review URL: https://codereview.chromium.org/605273004

4 years agoRename GN public variables.
Brett Wilson [Wed, 24 Sep 2014 22:32:49 +0000]
Rename GN public variables.

forward_dependent_configs_from => public_deps
direct_dependent_configs => public_configs

R=jam@chromium.org

Review URL: https://codereview.chromium.org/598093002

4 years agoLock page in LoadFXAnnot to prevent unintended page closing
Bo Xu [Wed, 24 Sep 2014 17:49:52 +0000]
Lock page in LoadFXAnnot to prevent unintended page closing

BUG=410326
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/594403003

4 years agoInvoke V8::Initialize() explicitly during V8 setup
Jochen Eisinger [Mon, 22 Sep 2014 06:46:17 +0000]
Invoke V8::Initialize() explicitly during V8 setup

BUG=none
R=jam@chromium.org

Review URL: https://codereview.chromium.org/581413002

4 years agoAdd FPDF_GetSecurityHandlerRevision
Bo Xu [Sat, 20 Sep 2014 02:16:31 +0000]
Add FPDF_GetSecurityHandlerRevision

Security handler revision number is needed to interpret file permission.

BUG=None
R=thestig@chromium.org

Review URL: https://codereview.chromium.org/589813002

4 years agoFix a bug when assign the generation number of indirect objects
Bo Xu [Fri, 19 Sep 2014 22:58:46 +0000]
Fix a bug when assign the generation number of indirect objects

BUG=408532
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/524443002

4 years agoAdjust the order of clearing resource in CPDF_DocPageData::Clear
Jun Fang [Fri, 19 Sep 2014 21:51:51 +0000]
Adjust the order of clearing resource in CPDF_DocPageData::Clear

Images are basic resource and are referred or used by other objects in some cases. Images should be released after the objects who uses these objects. In this case, an image object is accessed in the process of CPDF_TilingPattern's destroy. Unlikely, this image has been destroyed before.

BUG=414046
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/582993002

5 years agoFix Regression: Incomplete file loading is seen for multi page pdf files.
Tom Sepez [Thu, 18 Sep 2014 19:11:56 +0000]
Fix Regression: Incomplete file loading is seen for multi page pdf files.

This was introduced at PDFium revision 12a9940. There was a subtle logic
change for null |parray|.

BUG=415438
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/579363002

5 years agogn: don't remove -fno-exceptions to match gyp
Scott Graham [Thu, 18 Sep 2014 16:28:58 +0000]
gn: don't remove -fno-exceptions to match gyp

Not required since: https://code.google.com/p/pdfium/issues/detail?id=28

R=jam@chromium.org
BUG=chromium:335824

Review URL: https://codereview.chromium.org/567393004

5 years agoWhen forcing clear page data, no need to release colorspace when releasing pattern
Bo Xu [Tue, 16 Sep 2014 20:24:37 +0000]
When forcing clear page data, no need to release colorspace when releasing pattern

BUG=414661
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/572853006

5 years agoAdd a boundary check before accessing the table of 'Index to Location'
Jun Fang [Tue, 16 Sep 2014 04:50:59 +0000]
Add a boundary check before accessing the table of 'Index to Location'

Before this fix, only |gindex < face->num_locations| is checked. However, the pointer, p, will be moved to next location in the first FT_NEXT_ULONG or FT_NEXT_USHORT. It may cause a crashier. So a boundary check is needed before the second FT_NEXT_ULONG or FT_NEXT_USHORT.

BUG=412457
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/571833002

5 years agoCheck Null pointer in CPDF_Dictionary::GetUnicodeText
Bo Xu [Mon, 15 Sep 2014 18:28:25 +0000]
Check Null pointer in CPDF_Dictionary::GetUnicodeText

BUG=414155
R=thakis@chromium.org

Review URL: https://codereview.chromium.org/574463002

5 years agoFix hebrew character highlight issue in a special document
Bo Xu [Thu, 11 Sep 2014 21:26:42 +0000]
Fix hebrew character highlight issue in a special document

There is an image object and text objects in this document, but the character in each text object is reversed.
When rendering, the image object is shown.
However, when highlighting, the text object is selected, resulting in text index issue.
Moreover, the character in the document is in reading order, which is different from normal document.

BUG=pdfium:43
R=jbreiden@google.com

Review URL: https://codereview.chromium.org/484503002

5 years agoCheck object type for objects used in the dictory of 'Index'
Jun Fang [Wed, 10 Sep 2014 23:11:45 +0000]
Check object type for objects used in the dictory of 'Index'

BUG=387970
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/551503003

5 years agoChange the forced clear order of CPDF_DocPageData::Clear, and remove m_pDocument...
Bo Xu [Wed, 10 Sep 2014 01:39:30 +0000]
Change the forced clear order of CPDF_DocPageData::Clear, and remove m_pDocument in CPDF_Color

If not forced clear, the counter of CPDF_Pattern will take care the count of referenced instance.
When forced clear, clear color first to make sure pattern still exists when referencing it.

BUG=411154
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/554913003

5 years agoFix uninitialized value in CPDF_ColorStateData
Bo Xu [Wed, 10 Sep 2014 01:32:05 +0000]
Fix uninitialized value in CPDF_ColorStateData

BUG=411161
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/560673002

5 years agoRevert of Fix uninitialized value in CPDF_ColorStateData (patchset #1 id:1 of https...
Bo Xu [Wed, 10 Sep 2014 00:36:01 +0000]
Revert of Fix uninitialized value in CPDF_ColorStateData (patchset #1 id:1 of https://codereview.chromium.org/547863002/)

Reason for revert:
The initialized member variable is wrong. Needs to undo this.

Original issue's description:
> Fix uninitialized value in CPDF_ColorStateData
>
> BUG=411161
> R=tsepez@chromium.org
>
> Committed: https://pdfium.googlesource.com/pdfium/+/a38d4c3572b566f8e64b9ca4f725cbbc581e85ab

TBR=tsepez@chromium.org,jun_fang@foxitsoftware.com
NOTREECHECKS=true
NOTRY=true
BUG=411161

Review URL: https://codereview.chromium.org/558803004

5 years agoFix uninitialized value in CPDF_ColorStateData
Bo Xu [Tue, 9 Sep 2014 00:35:04 +0000]
Fix uninitialized value in CPDF_ColorStateData

BUG=411161
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/547863002

5 years agoFix un-initialized R G B value
Bo Xu [Tue, 9 Sep 2014 00:28:16 +0000]
Fix un-initialized R G B value

BUG=411163
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/551513005

5 years agoConvert GN visibility to be a list.
Brett Wilson [Mon, 8 Sep 2014 23:36:48 +0000]
Convert GN visibility to be a list.

GN visibility currently allows either string or list types, but this is causing
some problems for some templates. I'm going to require it to be lists, so am
changing all callers before pushing the new binary.

R=jam@chromium.org

Review URL: https://codereview.chromium.org/555523002

5 years agoMerge performance fix for cmsDupToneCurve from previous upstream branch.
Chris Palmer [Mon, 8 Sep 2014 23:12:10 +0000]
Merge performance fix for cmsDupToneCurve from previous upstream branch.

BUG=
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/534363002

5 years agoThe cause of this issue is that there is an indirect object like '112 0 R' but no...
Jun Fang [Mon, 8 Sep 2014 18:27:02 +0000]
The cause of this issue is that there is an indirect object like '112 0 R' but no its direct object '112 0 object' in the test pdf file. Without checking the validity, it causes a null pointer when trying to get the direct object by an indirect object.

BUG=390781
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/553613003

5 years agoAdd v8_platform to the JS dependencies in the GN build.
Brett Wilson [Thu, 4 Sep 2014 20:48:16 +0000]
Add v8_platform to the JS dependencies in the GN build.

This is required for the call to v8::platform::CreateDefaultPlatform.

R=jam@chromium.org

Review URL: https://codereview.chromium.org/540133002

5 years agoAllocate m_pCompData when |m_nComponents| is updated.
Bo Xu [Wed, 3 Sep 2014 20:30:43 +0000]
Allocate m_pCompData when |m_nComponents| is updated.

When |m_nComponents| is changed from loading stream information,
previously allocated memory that depends on |m_nComponents| needes to be freed
and allocated again to enforce memory size consistency.

BUG=409695
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/528163002

5 years agoCheck m_nComponents when using JBIG2Decode
Bo Xu [Tue, 2 Sep 2014 22:36:34 +0000]
Check m_nComponents when using JBIG2Decode

BUG=409692
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/534763002

5 years agoAdd m_pDocument in CPDF_Color and check if page date has been forced clear
Bo Xu [Tue, 2 Sep 2014 19:13:36 +0000]
Add m_pDocument in CPDF_Color and check if page date has been forced clear

This will prevent using freed pattern object.
This is a better solution than https://pdfium.googlesource.com/pdfium/+/1b9c5c4dc41956b8c5ab17b9a882adf8a2513768
and in essence revert that patch

BUG=409373
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/522483003

5 years agoTidy up opj_ callback functions in fx_codec_jpx_obj.cpp
Tom Sepez [Tue, 2 Sep 2014 17:27:47 +0000]
Tidy up opj_ callback functions in fx_codec_jpx_obj.cpp

This is code cleanup rather than bug fixing.

The motivation for this was to fix the casts at line 97 of the original file.  These are wrong; you cannot correct via casting a function signature mismatch when passing a function as an argument.  In theory, there's no reason to believe that the compiler will pass args in the same manner for a function of type (void*, size_t, void*) as for a function of type (void*, size_t, some_struct*).  The cast will suppress the compile error, but you can't be assured the call will work as intended.  In practice, it does, since the last architecture where a void* had a different representation than a struct* went extinct in the late 80s.

In the functions themselves, note that we currently bail out if srcData->offset >= srcData->src_size, so the expression
   bufferLength = (OPJ_SIZE_T)(srcData->src_size - srcData->offset)

will always be > 0.  Hence the check
   if(bufferLength <= 0)
is pointless, esp. since bufferLength is a signed type and < 0 makes no sense.

The opj_seek_from_memory() has a bool return value, so returning -1 on error doesn't seem reasonable.  Change this to TRUE/FALSE, and return false on seek past end.

If we're truly passing readonly data, then perhaps it makes sense to make the write() function always return -1. I didn't do this.

Lastly, I capitalize "DecodeData" so that it looks like a struct, and change its members to be size_t's to avoid casting back and forth.

R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/507273003

5 years agoRemove the GetValidBpc check in application callers and move it to where m_bpc is...
Bo Xu [Sun, 31 Aug 2014 22:23:46 +0000]
Remove the GetValidBpc check in application callers and move it to where m_bpc is assigned.

The problem of using GetValidBpc() in each function call is it could result in mismatch as seen in this case:
in ContinueToLoadMask(), m_bpc is re-assigned to 1 if m_bImageMask==1 regardless of the value from GetValidBpc().
This will result in mismatch if another function use the value from GetValidBpc().

The solution could be checking m_bImageMask in another function to make sure m_bpc is consistent, but that makes the code too cumbersome.
Also, we have to bring and are bringing in more and more GetValidBpc check, and this will continue with other buggy documents. So better to fix it now.

The original rational to use GetValidBpc() in where m_bpc is used is to respect the "raw" data from parsing.
However, if it will be ignored anyway and using value from GetValidBpc(), we'd better correct it at the very beginning.

BUG=408541
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/518443002

5 years agoRemove unused fields and stack locals.
Chris Palmer [Thu, 28 Aug 2014 21:44:46 +0000]
Remove unused fields and stack locals.

Edge closer to getting PDFium to build in chromium_code mode.

BUG=https://code.google.com/p/pdfium/issues/detail?id=29
R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/437343002

5 years agoNo need to release resources in destructor of CPDF_ShadingObject
Bo Xu [Thu, 28 Aug 2014 18:49:17 +0000]
No need to release resources in destructor of CPDF_ShadingObject

CPDF_DocPageData::~CPDF_DocPageData() will force to release all resources, so no need to do it here, which can result in heap-use-after-free trouble.

BUG=408164
R=jun_fang@foxitsoftware.com, tsepez@chromium.org

Review URL: https://codereview.chromium.org/513063003

5 years agoRestrict index not be greater than row_size in TIFF_PredictLine
Bo Xu [Wed, 27 Aug 2014 23:01:41 +0000]
Restrict index not be greater than row_size in TIFF_PredictLine

There is not strict way to limit invalid value of |Colors| from dictionary. We can make sure |index| does not go out of boundary of row_size.

BUG=407614
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/509993003

5 years agoUse valid bpc value in LoadPalette() and ContinueToLoadMask()
Bo Xu [Wed, 27 Aug 2014 21:19:55 +0000]
Use valid bpc value in LoadPalette() and ContinueToLoadMask()

BUG=408141, 408147
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/508253003

5 years agoFix a bug when looping through m_pCompData
Bo Xu [Wed, 27 Aug 2014 20:13:42 +0000]
Fix a bug when looping through m_pCompData

BUG=408154
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/509613005

5 years agoBounds check before fixed-size memcmp() in CJPX_Decoder::Init().
Tom Sepez [Tue, 26 Aug 2014 23:35:12 +0000]
Bounds check before fixed-size memcmp() in CJPX_Decoder::Init().

BUG=407476
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/489703004

5 years agoFix compile on mac: format string mismatch error.
Tom Sepez [Tue, 26 Aug 2014 21:03:25 +0000]
Fix compile on mac: format string mismatch error.

See http://build.chromium.org/p/tryserver.chromium.mac/builders/mac_chromium_compile_dbg/builds/9542/steps/compile%20%28with%20patch%29/logs/stdio

TBR=jun_fang@foxitsoftware.com,

Review URL: https://codereview.chromium.org/506053003

5 years agoSet m_pLinearized to NULL after release
Bo Xu [Mon, 25 Aug 2014 22:22:07 +0000]
Set m_pLinearized to NULL after release

BUG=406868
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/504993002

5 years agoPerform better input checks in early steps of parser.
Tom Sepez [Mon, 25 Aug 2014 21:59:02 +0000]
Perform better input checks in early steps of parser.

BUG=406591
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/501823003

5 years agoUse number of components from ICC profile and alternate color space
Bo Xu [Mon, 25 Aug 2014 20:45:17 +0000]
Use number of components from ICC profile and alternate color space

BUG=406806
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/503883002

5 years agoAdd GetValidBpc() check in CPDF_DIBSource::CreateDecoder()
Bo Xu [Mon, 25 Aug 2014 20:34:01 +0000]
Add GetValidBpc() check in CPDF_DIBSource::CreateDecoder()

BUG=406908
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/504673002

5 years agoAdd GetValidBpc() check in CPDF_DIBSource::GetScanLine
Bo Xu [Mon, 25 Aug 2014 20:31:16 +0000]
Add GetValidBpc() check in CPDF_DIBSource::GetScanLine

BUG=406600, 406895
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/497733005

5 years agoRevert of Use number of components from ICC profile and alternateCS (patchset #1...
Bo Xu [Mon, 25 Aug 2014 18:52:41 +0000]
Revert of Use number of components from ICC profile and alternateCS (patchset #1 of https://codereview.chromium.org/493163003/)

Reason for revert:
Needs to address comments before landing

Original issue's description:
> Use number of components from ICC profile and alternate color space
>
> BUG=406806
>
> Committed: https://pdfium.googlesource.com/pdfium/+/be83103

TBR=tsepez@chromium.org,jun_fang@foxitsoftware.com
NOTREECHECKS=true
NOTRY=true
BUG=406806

Review URL: https://codereview.chromium.org/504883003

5 years agoUse number of components from ICC profile and alternate color space
Bo Xu [Mon, 25 Aug 2014 17:01:19 +0000]
Use number of components from ICC profile and alternate color space

BUG=406806

Review URL: https://codereview.chromium.org/493163003

5 years agoFix the issue 'SEGV on unknown address in CPDF_DataAvail::GetObjectSize'
Jun Fang [Sat, 23 Aug 2014 00:06:32 +0000]
Fix the issue 'SEGV on unknown address in CPDF_DataAvail::GetObjectSize'

BUG=387983
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/454283002

5 years agoFix a hang issue due to inconsistent page number in the test file
Jun Fang [Sat, 23 Aug 2014 00:04:29 +0000]
Fix a hang issue due to inconsistent page number in the test file

Pdfium reads the page number from the field of '/Count' but it can't
load the number assigned by this field due to the damaged data. Add a
check to ensure that the required page should be one of loaded pages.

BUG=406090
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/477873003

5 years agoBounds check in CFX_Font::LoadGlyphPath().
Tom Sepez [Fri, 22 Aug 2014 23:07:58 +0000]
Bounds check in CFX_Font::LoadGlyphPath().

Add a check to CFX_Font::LoadGlyphPath() similar to the one that exists
in CFX_FaceCache::RenderGlyph().

Also replace some scattered magic numbers in the file with constants,
and make arrays not used outside this file be statically scoped.

BUG=406144
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/497863002

5 years agoFix confusion between length in bytes and length in characters in app::response().
Tom Sepez [Fri, 22 Aug 2014 22:52:05 +0000]
Fix confusion between length in bytes and length in characters in app::response().

I also clean up the code while we are here, rewriting a strange switch statement and tidying whitespace.

BUG=406142
R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/498773004

5 years agoDon't stretch bitmaps if destination size is empty.
Vitaly Buka [Fri, 22 Aug 2014 21:01:56 +0000]
Don't stretch bitmaps if destination size is empty.

BUG=405201
R=bo_xu@foxitsoftware.com

Review URL: https://codereview.chromium.org/474093003

5 years agoCheck the number of component in ICCBased colorspace
Bo Xu [Fri, 22 Aug 2014 17:30:10 +0000]
Check the number of component in ICCBased colorspace

From PDF reference 8.6.5.5, this could only be 1, 3 or 4.

BUG=387968
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/464083003