muhammara 2.6.0 → 2.6.2

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/node_modules/@mapbox/node-pre-gyp/CHANGELOG.md +3 -0
  3. package/node_modules/@mapbox/node-pre-gyp/README.md +1 -1
  4. package/node_modules/@mapbox/node-pre-gyp/package.json +5 -5
  5. package/node_modules/semver/classes/range.js +3 -0
  6. package/node_modules/semver/index.js +81 -41
  7. package/node_modules/semver/package.json +25 -14
  8. package/node_modules/tar/README.md +37 -9
  9. package/node_modules/tar/lib/create.js +16 -9
  10. package/node_modules/tar/lib/extract.js +16 -10
  11. package/node_modules/tar/lib/header.js +50 -34
  12. package/node_modules/tar/lib/large-numbers.js +22 -17
  13. package/node_modules/tar/lib/list.js +20 -13
  14. package/node_modules/tar/lib/mkdir.js +40 -24
  15. package/node_modules/tar/lib/mode-fix.js +8 -4
  16. package/node_modules/tar/lib/normalize-unicode.js +3 -2
  17. package/node_modules/tar/lib/pack.js +54 -31
  18. package/node_modules/tar/lib/parse.js +74 -46
  19. package/node_modules/tar/lib/path-reservations.js +26 -18
  20. package/node_modules/tar/lib/pax.js +15 -8
  21. package/node_modules/tar/lib/read-entry.js +14 -7
  22. package/node_modules/tar/lib/replace.js +50 -27
  23. package/node_modules/tar/lib/strip-absolute-path.js +1 -1
  24. package/node_modules/tar/lib/unpack.js +73 -44
  25. package/node_modules/tar/lib/update.js +8 -4
  26. package/node_modules/tar/lib/warn-mixin.js +7 -4
  27. package/node_modules/tar/lib/write-entry.js +44 -23
  28. package/node_modules/tar/package.json +44 -30
  29. package/package.json +1 -1
  30. package/src/deps/PDFWriter/CFFFileInput.cpp +7 -1
  31. package/src/deps/PDFWriter/DecryptionHelper.cpp +1 -1
  32. package/src/deps/PDFWriter/DocumentContext.cpp +21 -8
  33. package/src/deps/PDFWriter/DocumentContext.h +1 -1
  34. package/src/deps/PDFWriter/PDFModifiedPage.cpp +2 -0
  35. package/src/deps/PDFWriter/PDFPageInput.cpp +7 -1
  36. package/src/deps/PDFWriter/PDFParser.cpp +12 -0
  37. package/src/deps/PDFWriter/PDFUsedFont.cpp +4 -2
  38. package/src/deps/PDFWriter/TrueTypeEmbeddedFontWriter.cpp +15 -0
@@ -9,14 +9,17 @@ const r = require('./replace.js')
9
9
  module.exports = (opt_, files, cb) => {
10
10
  const opt = hlo(opt_)
11
11
 
12
- if (!opt.file)
12
+ if (!opt.file) {
13
13
  throw new TypeError('file is required')
14
+ }
14
15
 
15
- if (opt.gzip)
16
+ if (opt.gzip) {
16
17
  throw new TypeError('cannot append to compressed archives')
18
+ }
17
19
 
18
- if (!files || !Array.isArray(files) || !files.length)
20
+ if (!files || !Array.isArray(files) || !files.length) {
19
21
  throw new TypeError('no files or directories specified')
22
+ }
20
23
 
21
24
  files = Array.from(files)
22
25
 
@@ -27,8 +30,9 @@ module.exports = (opt_, files, cb) => {
27
30
  const mtimeFilter = opt => {
28
31
  const filter = opt.filter
29
32
 
30
- if (!opt.mtimeCache)
33
+ if (!opt.mtimeCache) {
31
34
  opt.mtimeCache = new Map()
35
+ }
32
36
 
33
37
  opt.filter = filter ? (path, stat) =>
34
38
  filter(path, stat) && !(opt.mtimeCache.get(path) > stat.mtime)
@@ -1,10 +1,12 @@
1
1
  'use strict'
2
2
  module.exports = Base => class extends Base {
3
3
  warn (code, message, data = {}) {
4
- if (this.file)
4
+ if (this.file) {
5
5
  data.file = this.file
6
- if (this.cwd)
6
+ }
7
+ if (this.cwd) {
7
8
  data.cwd = this.cwd
9
+ }
8
10
  data.code = message instanceof Error && message.code || code
9
11
  data.tarCode = code
10
12
  if (!this.strict && data.recoverable !== false) {
@@ -13,9 +15,10 @@ module.exports = Base => class extends Base {
13
15
  message = message.message
14
16
  }
15
17
  this.emit('warn', data.tarCode, message, data)
16
- } else if (message instanceof Error)
18
+ } else if (message instanceof Error) {
17
19
  this.emit('error', Object.assign(message, data))
18
- else
20
+ } else {
19
21
  this.emit('error', Object.assign(new Error(`${code}: ${message}`), data))
22
+ }
20
23
  }
21
24
  }
@@ -8,8 +8,9 @@ const normPath = require('./normalize-windows-path.js')
8
8
  const stripSlash = require('./strip-trailing-slashes.js')
9
9
 
10
10
  const prefixPath = (path, prefix) => {
11
- if (!prefix)
11
+ if (!prefix) {
12
12
  return normPath(path)
13
+ }
13
14
  path = normPath(path).replace(/^\.(\/|$)/, '')
14
15
  return stripSlash(prefix) + '/' + path
15
16
  }
@@ -44,8 +45,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
44
45
  constructor (p, opt) {
45
46
  opt = opt || {}
46
47
  super(opt)
47
- if (typeof p !== 'string')
48
+ if (typeof p !== 'string') {
48
49
  throw new TypeError('path is required')
50
+ }
49
51
  this.path = normPath(p)
50
52
  // suppress atime, ctime, uid, gid, uname, gname
51
53
  this.portable = !!opt.portable
@@ -72,8 +74,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
72
74
  this.pos = null
73
75
  this.remain = null
74
76
 
75
- if (typeof opt.onwarn === 'function')
77
+ if (typeof opt.onwarn === 'function') {
76
78
  this.on('warn', opt.onwarn)
79
+ }
77
80
 
78
81
  let pathWarn = false
79
82
  if (!this.preservePaths) {
@@ -94,8 +97,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
94
97
 
95
98
  this.absolute = normPath(opt.absolute || path.resolve(this.cwd, p))
96
99
 
97
- if (this.path === '')
100
+ if (this.path === '') {
98
101
  this.path = './'
102
+ }
99
103
 
100
104
  if (pathWarn) {
101
105
  this.warn('TAR_ENTRY_INFO', `stripping ${pathWarn} from absolute path`, {
@@ -104,22 +108,25 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
104
108
  })
105
109
  }
106
110
 
107
- if (this.statCache.has(this.absolute))
111
+ if (this.statCache.has(this.absolute)) {
108
112
  this[ONLSTAT](this.statCache.get(this.absolute))
109
- else
113
+ } else {
110
114
  this[LSTAT]()
115
+ }
111
116
  }
112
117
 
113
118
  emit (ev, ...data) {
114
- if (ev === 'error')
119
+ if (ev === 'error') {
115
120
  this[HAD_ERROR] = true
121
+ }
116
122
  return super.emit(ev, ...data)
117
123
  }
118
124
 
119
125
  [LSTAT] () {
120
126
  fs.lstat(this.absolute, (er, stat) => {
121
- if (er)
127
+ if (er) {
122
128
  return this.emit('error', er)
129
+ }
123
130
  this[ONLSTAT](stat)
124
131
  })
125
132
  }
@@ -127,8 +134,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
127
134
  [ONLSTAT] (stat) {
128
135
  this.statCache.set(this.absolute, stat)
129
136
  this.stat = stat
130
- if (!stat.isFile())
137
+ if (!stat.isFile()) {
131
138
  stat.size = 0
139
+ }
132
140
  this.type = getType(stat)
133
141
  this.emit('stat', stat)
134
142
  this[PROCESS]()
@@ -153,8 +161,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
153
161
  }
154
162
 
155
163
  [HEADER] () {
156
- if (this.type === 'Directory' && this.portable)
164
+ if (this.type === 'Directory' && this.portable) {
157
165
  this.noMtime = true
166
+ }
158
167
 
159
168
  this.header = new Header({
160
169
  path: this[PREFIX](this.path),
@@ -196,8 +205,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
196
205
  }
197
206
 
198
207
  [DIRECTORY] () {
199
- if (this.path.substr(-1) !== '/')
208
+ if (this.path.slice(-1) !== '/') {
200
209
  this.path += '/'
210
+ }
201
211
  this.stat.size = 0
202
212
  this[HEADER]()
203
213
  this.end()
@@ -205,8 +215,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
205
215
 
206
216
  [SYMLINK] () {
207
217
  fs.readlink(this.absolute, (er, linkpath) => {
208
- if (er)
218
+ if (er) {
209
219
  return this.emit('error', er)
220
+ }
210
221
  this[ONREADLINK](linkpath)
211
222
  })
212
223
  }
@@ -230,31 +241,35 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
230
241
  const linkKey = this.stat.dev + ':' + this.stat.ino
231
242
  if (this.linkCache.has(linkKey)) {
232
243
  const linkpath = this.linkCache.get(linkKey)
233
- if (linkpath.indexOf(this.cwd) === 0)
244
+ if (linkpath.indexOf(this.cwd) === 0) {
234
245
  return this[HARDLINK](linkpath)
246
+ }
235
247
  }
236
248
  this.linkCache.set(linkKey, this.absolute)
237
249
  }
238
250
 
239
251
  this[HEADER]()
240
- if (this.stat.size === 0)
252
+ if (this.stat.size === 0) {
241
253
  return this.end()
254
+ }
242
255
 
243
256
  this[OPENFILE]()
244
257
  }
245
258
 
246
259
  [OPENFILE] () {
247
260
  fs.open(this.absolute, 'r', (er, fd) => {
248
- if (er)
261
+ if (er) {
249
262
  return this.emit('error', er)
263
+ }
250
264
  this[ONOPENFILE](fd)
251
265
  })
252
266
  }
253
267
 
254
268
  [ONOPENFILE] (fd) {
255
269
  this.fd = fd
256
- if (this[HAD_ERROR])
270
+ if (this[HAD_ERROR]) {
257
271
  return this[CLOSE]()
272
+ }
258
273
 
259
274
  this.blockLen = 512 * Math.ceil(this.stat.size / 512)
260
275
  this.blockRemain = this.blockLen
@@ -318,10 +333,11 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
318
333
  this.buf : this.buf.slice(this.offset, this.offset + bytesRead)
319
334
 
320
335
  const flushed = this.write(writeBuf)
321
- if (!flushed)
336
+ if (!flushed) {
322
337
  this[AWAITDRAIN](() => this[ONDRAIN]())
323
- else
338
+ } else {
324
339
  this[ONDRAIN]()
340
+ }
325
341
  }
326
342
 
327
343
  [AWAITDRAIN] (cb) {
@@ -343,8 +359,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
343
359
 
344
360
  [ONDRAIN] () {
345
361
  if (!this.remain) {
346
- if (this.blockRemain)
362
+ if (this.blockRemain) {
347
363
  super.write(Buffer.alloc(this.blockRemain))
364
+ }
348
365
  return this[CLOSE](er => er ? this.emit('error', er) : this.end())
349
366
  }
350
367
 
@@ -412,8 +429,9 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
412
429
 
413
430
  this.readEntry = readEntry
414
431
  this.type = readEntry.type
415
- if (this.type === 'Directory' && this.portable)
432
+ if (this.type === 'Directory' && this.portable) {
416
433
  this.noMtime = true
434
+ }
417
435
 
418
436
  this.prefix = opt.prefix || null
419
437
 
@@ -429,8 +447,9 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
429
447
  this.ctime = this.portable ? null : readEntry.ctime
430
448
  this.linkpath = normPath(readEntry.linkpath)
431
449
 
432
- if (typeof opt.onwarn === 'function')
450
+ if (typeof opt.onwarn === 'function') {
433
451
  this.on('warn', opt.onwarn)
452
+ }
434
453
 
435
454
  let pathWarn = false
436
455
  if (!this.preservePaths) {
@@ -500,15 +519,17 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
500
519
 
501
520
  write (data) {
502
521
  const writeLen = data.length
503
- if (writeLen > this.blockRemain)
522
+ if (writeLen > this.blockRemain) {
504
523
  throw new Error('writing more to entry than is appropriate')
524
+ }
505
525
  this.blockRemain -= writeLen
506
526
  return super.write(data)
507
527
  }
508
528
 
509
529
  end () {
510
- if (this.blockRemain)
530
+ if (this.blockRemain) {
511
531
  super.write(Buffer.alloc(this.blockRemain))
532
+ }
512
533
  return super.end()
513
534
  }
514
535
  })
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "_from": "tar@^6.1.11",
3
- "_id": "tar@6.1.11",
3
+ "_id": "tar@6.1.12",
4
4
  "_inBundle": false,
5
- "_integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==",
5
+ "_integrity": "sha512-jU4TdemS31uABHd+Lt5WEYJuzn+TJTCBLljvIAHZOz6M9Os5pJ4dD+vRFLxPa/n3T0iEFzpi+0x1UfuDZYbRMw==",
6
6
  "_location": "/tar",
7
7
  "_phantomChildren": {},
8
8
  "_requested": {
@@ -18,14 +18,12 @@
18
18
  "_requiredBy": [
19
19
  "/@mapbox/node-pre-gyp"
20
20
  ],
21
- "_resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz",
22
- "_shasum": "6760a38f003afa1b2ffd0ffe9e9abbd0eab3d621",
21
+ "_resolved": "https://registry.npmjs.org/tar/-/tar-6.1.12.tgz",
22
+ "_shasum": "3b742fb05669b55671fb769ab67a7791ea1a62e6",
23
23
  "_spec": "tar@^6.1.11",
24
24
  "_where": "/home/runner/work/MuhammaraJS/MuhammaraJS/node_modules/@mapbox/node-pre-gyp",
25
25
  "author": {
26
- "name": "Isaac Z. Schlueter",
27
- "email": "i@izs.me",
28
- "url": "http://blog.izs.me/"
26
+ "name": "GitHub Inc."
29
27
  },
30
28
  "bugs": {
31
29
  "url": "https://github.com/npm/node-tar/issues"
@@ -42,26 +40,23 @@
42
40
  "deprecated": false,
43
41
  "description": "tar for node",
44
42
  "devDependencies": {
43
+ "@npmcli/eslint-config": "^4.0.0",
44
+ "@npmcli/template-oss": "4.8.0",
45
45
  "chmodr": "^1.2.0",
46
46
  "end-of-stream": "^1.4.3",
47
- "eslint": "^7.17.0",
48
- "eslint-plugin-import": "^2.22.1",
49
- "eslint-plugin-node": "^11.1.0",
50
- "eslint-plugin-promise": "^4.2.1",
51
- "eslint-plugin-standard": "^5.0.0",
52
47
  "events-to-array": "^1.1.2",
53
48
  "mutate-fs": "^2.1.1",
54
- "rimraf": "^2.7.1",
55
- "tap": "^15.0.9",
56
- "tar-fs": "^1.16.3",
57
- "tar-stream": "^1.6.2"
49
+ "nock": "^13.2.9",
50
+ "rimraf": "^3.0.2",
51
+ "tap": "^16.0.1"
58
52
  },
59
53
  "engines": {
60
- "node": ">= 10"
54
+ "node": ">=10"
61
55
  },
62
56
  "files": [
63
- "index.js",
64
- "lib/*.js"
57
+ "bin/",
58
+ "lib/",
59
+ "index.js"
65
60
  ],
66
61
  "homepage": "https://github.com/npm/node-tar#readme",
67
62
  "license": "ISC",
@@ -71,22 +66,41 @@
71
66
  "url": "git+https://github.com/npm/node-tar.git"
72
67
  },
73
68
  "scripts": {
74
- "bench": "for i in benchmarks/*/*.js; do echo $i; for j in {1..5}; do node $i || break; done; done",
75
- "eslint": "eslint",
76
69
  "genparse": "node scripts/generate-parse-fixtures.js",
77
- "lint": "npm run eslint -- test lib",
70
+ "lint": "eslint \"**/*.js\"",
78
71
  "lintfix": "npm run lint -- --fix",
72
+ "postlint": "template-oss-check",
79
73
  "posttest": "npm run lint",
80
- "postversion": "npm publish",
81
- "prepublishOnly": "git push origin --follow-tags",
82
- "preversion": "npm test",
83
- "test": "node test/fixtures/test.js",
84
- "test:posix": "tap",
85
- "test:win32": "tap --lines=98 --branches=98 --statements=98 --functions=98"
74
+ "snap": "tap",
75
+ "template-oss-apply": "template-oss-apply --force",
76
+ "test": "tap"
86
77
  },
87
78
  "tap": {
88
79
  "coverage-map": "map.js",
89
- "check-coverage": true
80
+ "timeout": 0,
81
+ "nyc-arg": [
82
+ "--exclude",
83
+ "tap-snapshots/**"
84
+ ]
90
85
  },
91
- "version": "6.1.11"
86
+ "templateOSS": {
87
+ "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
88
+ "version": "4.8.0",
89
+ "content": "scripts/template-oss",
90
+ "engines": ">=10",
91
+ "distPaths": [
92
+ "index.js"
93
+ ],
94
+ "allowPaths": [
95
+ "/index.js"
96
+ ],
97
+ "ciVersions": [
98
+ "10.x",
99
+ "12.x",
100
+ "14.x",
101
+ "16.x",
102
+ "18.x"
103
+ ]
104
+ },
105
+ "version": "6.1.12"
92
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muhammara",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
4
4
  "description": "Create, read and modify PDF files and streams. A drop in replacement for hummujs 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();
@@ -352,6 +352,12 @@ EStatusCode PDFParser::ParseLastXrefPosition()
352
352
  mObjectParser.ResetReadState();
353
353
  RefCountPtr<PDFObject> anObject(mObjectParser.ParseNewObject());
354
354
 
355
+ if (!anObject) {
356
+ status = PDFHummus::eFailure;
357
+ TRACE_LOG("PDFParser::ParseXrefPosition: Unable to find any object");
358
+ break;
359
+ }
360
+
355
361
  if(anObject->GetType() == PDFObject::ePDFObjectInteger)
356
362
  {
357
363
  mLastXrefPosition = (LongFilePositionType)((PDFInteger*)anObject.GetPtr())->GetValue();
@@ -384,6 +390,12 @@ EStatusCode PDFParser::ParseLastXrefPosition()
384
390
  while(!foundStartXref && mStream->NotEnded())
385
391
  {
386
392
  PDFObjectCastPtr<PDFSymbol> startxRef(mObjectParser.ParseNewObject());
393
+ if(!startxRef)
394
+ {
395
+ status = PDFHummus::eFailure;
396
+ TRACE_LOG("PDFParser::ParseXrefPosition, syntax error in reading xref position");
397
+ break;
398
+ }
387
399
  foundStartXref = startxRef.GetPtr() && (startxRef->GetValue() == scStartxref);
388
400
  }
389
401
 
@@ -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;