muhammara 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.4.0] - 2022-11-24
11
+
12
+ ### Added
13
+
14
+ - Electron 21.3.x
15
+
16
+ ### Fixed
17
+
18
+ - Several cases of NPE under different circumstances
19
+
10
20
  ## [3.3.0] - 2022-11-05
11
21
 
12
22
  ### Fixed
@@ -72,6 +82,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
72
82
  - Node < 11 and Electron < 11 removed
73
83
  - Renamed typo exported value from eTokenSeprator to eTokenSeparator
74
84
 
85
+ ## [2.6.2] - 2022-11-23
86
+
87
+ ### Fixed
88
+
89
+ - Several cases of NPE under different circumstances
90
+
75
91
  ## [2.6.1] - 2022-10-23
76
92
 
77
93
  ### Fixed
@@ -310,12 +326,14 @@ with the following changes.
310
326
 
311
327
  - Initial release
312
328
 
313
- [unreleased]: https://github.com/julianhille/MuhammaraJS/compare/3.3.0...HEAD
329
+ [unreleased]: https://github.com/julianhille/MuhammaraJS/compare/3.4.0...HEAD
330
+ [3.4.0]: https://github.com/julianhille/MuhammaraJS/compare/3.3.0...3.4.0
314
331
  [3.3.0]: https://github.com/julianhille/MuhammaraJS/compare/3.2.0...3.3.0
315
332
  [3.2.0]: https://github.com/julianhille/MuhammaraJS/compare/3.1.1...3.2.0
316
333
  [3.1.1]: https://github.com/julianhille/MuhammaraJS/compare/3.1.0...3.1.1
317
334
  [3.1.0]: https://github.com/julianhille/MuhammaraJS/compare/3.0.0...3.1.0
318
- [3.0.0]: https://github.com/julianhille/MuhammaraJS/compare/2.6.1...3.0.0
335
+ [3.0.0]: https://github.com/julianhille/MuhammaraJS/compare/2.6.2...3.0.0
336
+ [2.6.2]: https://github.com/julianhille/MuhammaraJS/compare/2.6.1...2.6.2
319
337
  [2.6.1]: https://github.com/julianhille/MuhammaraJS/compare/2.6.0...2.6.1
320
338
  [2.6.0]: https://github.com/julianhille/MuhammaraJS/compare/2.5.0...2.6.0
321
339
  [2.5.0]: https://github.com/julianhille/MuhammaraJS/compare/2.4.0...2.5.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muhammara",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Create, read and modify PDF files and streams. A drop in replacement for hummusjs PDF library",
5
5
  "homepage": "https://github.com/julianhille/Muhammarajs",
6
6
  "license": "Apache-2.0",
@@ -1018,7 +1018,13 @@ EStatusCode CFFFileInput::CalculateDependenciesForCharIndex(unsigned short inFon
1018
1018
  if(status != PDFHummus::eFailure)
1019
1019
  {
1020
1020
  mCurrentDependencies = &ioDependenciesInfo;
1021
- return interpreter.Intepret(*GetGlyphCharString(inFontIndex,inCharStringIndex),this);
1021
+ CharString* charString = GetGlyphCharString(inFontIndex,inCharStringIndex);
1022
+ if(!charString)
1023
+ {
1024
+ TRACE_LOG("GetGlyphCharString cannot find char string");
1025
+ return PDFHummus::eFailure;
1026
+ }
1027
+ return interpreter.Intepret(*charString, this);
1022
1028
  }
1023
1029
  else
1024
1030
  return status;
@@ -409,7 +409,7 @@ XCryptionCommon* DecryptionHelper::GetCryptForStream(PDFStreamInput* inStream) {
409
409
  for (; i < filterObjectArray->GetLength(); ++i)
410
410
  {
411
411
  PDFObjectCastPtr<PDFName> filterObjectItem(filterObjectArray->QueryObject(i));
412
- if (filterObjectItem->GetValue() == "Crypt")
412
+ if (!filterObjectItem || filterObjectItem->GetValue() == "Crypt")
413
413
  break;
414
414
  }
415
415
  if (i < filterObjectArray->GetLength()) {
@@ -2176,7 +2176,7 @@ EStatusCode DocumentContext::SetupModifiedFile(PDFParser* inModifiedFileParser)
2176
2176
  if(idArray.GetPtr() && idArray->GetLength() == 2)
2177
2177
  {
2178
2178
  PDFObjectCastPtr<PDFHexString> firstID = idArray->QueryObject(0);
2179
- if(firstID.GetPtr())
2179
+ if(firstID != NULL && firstID.GetPtr())
2180
2180
  mModifiedDocumentID = firstID->GetValue();
2181
2181
  }
2182
2182
 
@@ -2300,6 +2300,10 @@ EStatusCode DocumentContext::FinalizeModifiedPDF(PDFParser* inModifiedFileParser
2300
2300
  {
2301
2301
  // use an extender to copy original catalog elements and update version if required
2302
2302
  PDFDocumentCopyingContext* copyingContext = CreatePDFCopyingContext(inModifiedFileParser);
2303
+ if(!copyingContext) {
2304
+ status = eFailure;
2305
+ break;
2306
+ }
2303
2307
  ModifiedDocCatalogWriterExtension catalogUpdate(copyingContext,requiresVersionUpdate,inModifiedPDFVersion);
2304
2308
  status = WriteCatalogObject(finalPageRoot,&catalogUpdate);
2305
2309
  delete copyingContext;
@@ -2311,8 +2315,9 @@ EStatusCode DocumentContext::FinalizeModifiedPDF(PDFParser* inModifiedFileParser
2311
2315
  WriteInfoDictionary();
2312
2316
 
2313
2317
  // write encryption dictionary, if encrypting
2314
- CopyEncryptionDictionary(inModifiedFileParser);
2315
-
2318
+ status = CopyEncryptionDictionary(inModifiedFileParser);
2319
+ if(status != eSuccess)
2320
+ break;
2316
2321
  if(RequiresXrefStream(inModifiedFileParser))
2317
2322
  {
2318
2323
  status = WriteXrefStream(xrefTablePosition);
@@ -2398,8 +2403,11 @@ bool DocumentContext::DocumentHasNewPages()
2398
2403
  hasLeafs = pageTreeRoot->IsLeafParent();
2399
2404
  if(pageTreeRoot->GetNodesCount() == 0)
2400
2405
  break;
2401
- else
2406
+ else {
2402
2407
  pageTreeRoot = pageTreeRoot->GetPageTreeChild(0);
2408
+ if (!pageTreeRoot)
2409
+ break;
2410
+ }
2403
2411
  }
2404
2412
 
2405
2413
  return hasLeafs;
@@ -2526,12 +2534,12 @@ bool DocumentContext::DoExtendersRequireCatalogUpdate(PDFParser* inModifiedFileP
2526
2534
  return isUpdateRequired;
2527
2535
  }
2528
2536
 
2529
- void DocumentContext::CopyEncryptionDictionary(PDFParser* inModifiedFileParser)
2537
+ EStatusCode DocumentContext::CopyEncryptionDictionary(PDFParser* inModifiedFileParser)
2530
2538
  {
2531
2539
  // Reuse original encryption dict for new modified trailer. for sake of simplicity (with trailer using ref for encrypt), make it indirect if not already
2532
2540
  RefCountPtr<PDFObject> encrypt(inModifiedFileParser->GetTrailer()->QueryDirectObject("Encrypt"));
2533
2541
  if (encrypt.GetPtr() == NULL)
2534
- return;
2542
+ return eSuccess;
2535
2543
 
2536
2544
  if (encrypt->GetType() == PDFObject::ePDFObjectIndirectObjectReference)
2537
2545
  {
@@ -2540,11 +2548,15 @@ void DocumentContext::CopyEncryptionDictionary(PDFParser* inModifiedFileParser)
2540
2548
  }
2541
2549
  else
2542
2550
  {
2551
+ // copying context, write as is
2552
+ PDFDocumentCopyingContext* copyingContext = CreatePDFCopyingContext(inModifiedFileParser);
2553
+ if(!copyingContext) {
2554
+ return eFailure;
2555
+ }
2543
2556
  // copy to indirect object and set refrence
2544
2557
  mEncryptionHelper.PauseEncryption();
2545
2558
  ObjectIDType encryptionDictionaryID = mObjectsContext->StartNewIndirectObject();
2546
- // copying context, write as is
2547
- PDFDocumentCopyingContext* copyingContext = CreatePDFCopyingContext(inModifiedFileParser);
2559
+
2548
2560
  copyingContext->CopyDirectObjectAsIs(encrypt.GetPtr());
2549
2561
  delete copyingContext;
2550
2562
  mObjectsContext->EndIndirectObject();
@@ -2552,6 +2564,7 @@ void DocumentContext::CopyEncryptionDictionary(PDFParser* inModifiedFileParser)
2552
2564
 
2553
2565
  mTrailerInformation.SetEncrypt(encryptionDictionaryID);
2554
2566
  }
2567
+ return eSuccess;
2555
2568
  }
2556
2569
 
2557
2570
  bool DocumentContext::RequiresXrefStream(PDFParser* inModifiedFileParser)
@@ -432,7 +432,7 @@ namespace PDFHummus
432
432
  ObjectIDType WriteCombinedPageTree(PDFParser* inModifiedFileParser);
433
433
  bool IsRequiredVersionHigherThanPDFVersion(PDFParser* inModifiedFileParser,EPDFVersion inModifiedPDFVersion);
434
434
  bool DoExtendersRequireCatalogUpdate(PDFParser* inModifiedFileParser);
435
- void CopyEncryptionDictionary(PDFParser* inModifiedFileParser);
435
+ PDFHummus::EStatusCode CopyEncryptionDictionary(PDFParser* inModifiedFileParser);
436
436
  bool RequiresXrefStream(PDFParser* inModifiedFileParser);
437
437
  PDFHummus::EStatusCode WriteXrefStream(LongFilePositionType& outXrefPosition);
438
438
  HummusImageInformation& GetImageInformationStructFor(const std::string& inImageFile,unsigned long inImageIndex);
@@ -163,6 +163,8 @@ PDFHummus::EStatusCode PDFModifiedPage::WritePage()
163
163
  // get the page object
164
164
  ObjectIDType pageObjectID = copyingContext->GetSourceDocumentParser()->GetPageObjectID(mPageIndex);
165
165
  PDFObjectCastPtr<PDFDictionary> pageDictionaryObject = copyingContext->GetSourceDocumentParser()->ParsePage(mPageIndex);
166
+ if (!pageDictionaryObject)
167
+ return eFailure;
166
168
  MapIterator<PDFNameToPDFObjectMap> pageDictionaryObjectIt = pageDictionaryObject->GetIterator();
167
169
 
168
170
  // create modified page object
@@ -181,7 +181,13 @@ void PDFPageInput::SetPDFRectangleFromPDFArray(PDFArray* inPDFArray,PDFRectangle
181
181
  RefCountPtr<PDFObject> lowerLeftY(inPDFArray->QueryObject(1));
182
182
  RefCountPtr<PDFObject> upperRightX(inPDFArray->QueryObject(2));
183
183
  RefCountPtr<PDFObject> upperRightY(inPDFArray->QueryObject(3));
184
-
184
+ if (!lowerLeftX || !lowerLeftY || !upperRightX || !upperRightY)
185
+ {
186
+ // not sure if just a return is a good idea here.
187
+ // Things wont jus work and might go unnoticed
188
+ TRACE_LOG("Could not apply pdf rectangle as values are NULL");
189
+ return;
190
+ }
185
191
  outPDFRectangle.LowerLeftX = ParsedPrimitiveHelper(lowerLeftX.GetPtr()).GetAsDouble();
186
192
  outPDFRectangle.LowerLeftY = ParsedPrimitiveHelper(lowerLeftY.GetPtr()).GetAsDouble();
187
193
  outPDFRectangle.UpperRightX = ParsedPrimitiveHelper(upperRightX.GetPtr()).GetAsDouble();
@@ -396,6 +396,12 @@ EStatusCode PDFParser::ParseLastXrefPosition()
396
396
  while(!foundStartXref && mStream->NotEnded())
397
397
  {
398
398
  PDFObjectCastPtr<PDFSymbol> startxRef(mObjectParser.ParseNewObject());
399
+ if(!startxRef)
400
+ {
401
+ status = PDFHummus::eFailure;
402
+ TRACE_LOG("PDFParser::ParseXrefPosition, syntax error in reading xref position");
403
+ break;
404
+ }
399
405
  foundStartXref = startxRef.GetPtr() && (startxRef->GetValue() == scStartxref);
400
406
  }
401
407
 
@@ -68,7 +68,8 @@ EStatusCode PDFUsedFont::EncodeStringForShowing(const GlyphUnicodeMappingList& i
68
68
 
69
69
  if(!mWrittenFont)
70
70
  mWrittenFont = mFaceWrapper.CreateWrittenFontObject(mObjectsContext,mEmbedFont);
71
-
71
+ if(!mWrittenFont)
72
+ return PDFHummus::eFailure;
72
73
  mWrittenFont->AppendGlyphs(inText,outCharactersToUse,outTreatCharactersAsCID,outFontObjectToUse);
73
74
 
74
75
  return PDFHummus::eSuccess;
@@ -108,7 +109,8 @@ EStatusCode PDFUsedFont::EncodeStringsForShowing(const GlyphUnicodeMappingListLi
108
109
 
109
110
  if(!mWrittenFont)
110
111
  mWrittenFont = mFaceWrapper.CreateWrittenFontObject(mObjectsContext,mEmbedFont);
111
-
112
+ if(!mWrittenFont)
113
+ return PDFHummus::eFailure;
112
114
  mWrittenFont->AppendGlyphs(inText,outCharactersToUse,outTreatCharactersAsCID,outFontObjectToUse);
113
115
 
114
116
  return PDFHummus::eSuccess;
@@ -416,6 +416,9 @@ EStatusCode TrueTypeEmbeddedFontWriter::WriteHead()
416
416
  // and store the offset to the checksum
417
417
 
418
418
  TableEntry* tableEntry = mTrueTypeInput.GetTableEntry("head");
419
+ if (!tableEntry) {
420
+ return PDFHummus::eFailure;
421
+ }
419
422
  LongFilePositionType startTableOffset;
420
423
  OutputStreamTraits streamCopier(&mFontFileStream);
421
424
  LongFilePositionType endOfStream;
@@ -485,6 +488,9 @@ EStatusCode TrueTypeEmbeddedFontWriter::WriteHHea()
485
488
  // count is lower
486
489
 
487
490
  TableEntry* tableEntry = mTrueTypeInput.GetTableEntry("hhea");
491
+ if (!tableEntry) {
492
+ return PDFHummus::eFailure;
493
+ }
488
494
  LongFilePositionType startTableOffset;
489
495
  OutputStreamTraits streamCopier(&mFontFileStream);
490
496
  LongFilePositionType endOfStream;
@@ -556,6 +562,9 @@ EStatusCode TrueTypeEmbeddedFontWriter::WriteMaxp()
556
562
  // copy as is, then adjust the glyphs count
557
563
 
558
564
  TableEntry* tableEntry = mTrueTypeInput.GetTableEntry("maxp");
565
+ if (!tableEntry) {
566
+ return PDFHummus::eFailure;
567
+ }
559
568
  LongFilePositionType startTableOffset;
560
569
  OutputStreamTraits streamCopier(&mFontFileStream);
561
570
  LongFilePositionType endOfStream;
@@ -602,6 +611,9 @@ EStatusCode TrueTypeEmbeddedFontWriter::WriteGlyf(const UIntVector& inSubsetGlyp
602
611
  // while at it...update the locaTable
603
612
 
604
613
  TableEntry* tableEntry = mTrueTypeInput.GetTableEntry("glyf");
614
+ if (!tableEntry) {
615
+ return PDFHummus::eFailure;
616
+ }
605
617
  LongFilePositionType startTableOffset = mFontFileStream.GetCurrentPosition();
606
618
  UIntVector::const_iterator it = inSubsetGlyphIDs.begin();
607
619
  OutputStreamTraits streamCopier(&mFontFileStream);
@@ -706,6 +718,9 @@ EStatusCode TrueTypeEmbeddedFontWriter::CreateTableCopy(const char* inTableName,
706
718
  // copy as is, no adjustments required
707
719
 
708
720
  TableEntry* tableEntry = mTrueTypeInput.GetTableEntry(inTableName);
721
+ if (!tableEntry) {
722
+ return PDFHummus::eFailure;
723
+ }
709
724
  LongFilePositionType startTableOffset;
710
725
  OutputStreamTraits streamCopier(&mFontFileStream);
711
726
  LongFilePositionType endOfStream;