Skip to content
Snippets Groups Projects
Commit 9b8b6ac6 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

getPDFSignatureCount: fix "too much recursion" error with some PDFs

The regex used to detect signatures uses "(.|\\s)" to emulate dotall, since
old browsers don't support it.

For some reason that leads to internal errors in Firefox with larger files in some cases.

Replacing it with a simpler "[\\s\\S]" class makes things work.

Also adds some tests with real PDF files, "QPDF-367-0.pdf" was triggering this issue.

Fixes #46
parent 5c15f2c0
No related branches found
No related tags found
1 merge request!69getPDFSignatureCount: fix "too much recursion" error with some PDFs
......@@ -9,7 +9,8 @@ module.exports = function (config) {
},
files: [
{pattern: './*.js', included: true, watched: true, served: true, type: 'module'},
{pattern: './**/*', included: false, watched: true, served: true},
// XXX: nocache is required or karma serves garbage binary data for some reason
{pattern: './**/*', included: false, watched: true, served: true, nocache: true},
],
autoWatch: true,
browsers: ['ChromiumHeadlessNoSandbox', 'FirefoxHeadless'],
......
......@@ -183,6 +183,14 @@ Dependencies:
emitFiles: true,
fileName: 'shared/[name].[hash][extname]',
}),
appEnv == 'test' && copy({
targets: [
{
src: 'test/data/*',
dest: 'dist/test',
},
]
}),
copy({
targets: [
{
......
......@@ -132,7 +132,7 @@ export const readArrayBufferFileContent = async (file) => {
*/
export const getPDFSignatureCount = async (file) => {
const sigRegex = new RegExp(
'/Type\\s*/Sig(.|\\s)*?/SubFilter\\s*(/ETSI\\.CAdES\\.detached|/adbe\\.pkcs7\\.detached)',
'/Type\\s*/Sig[\\s\\S]*?/SubFilter\\s*(/ETSI\\.CAdES\\.detached|/adbe\\.pkcs7\\.detached)',
'g'
);
const content = await readBinaryFileContent(file);
......
File added
QPDF-367-0.pdf:
From https://corpora.tika.apache.org/base/packaged/pdfs/archive/pdfs_202002/qpdf.zip
\ No newline at end of file
File added
File added
......@@ -66,4 +66,18 @@ suite('pdf signature detection', () => {
assert((await getPDFSignatureCount(getPDFFile('foobar'))) === 0);
assert((await getPDFSignatureCount(getPDFFile(''))) === 0);
});
test('getPDFSignatureCount real files', async () => {
async function getRealPDFFile(name) {
let url = new URL('test/' + name, import.meta.url).href;
let resp = await fetch(url);
assert(resp.ok);
return getPDFFile(await resp.arrayBuffer());
}
assert.equal((await getPDFSignatureCount(await getRealPDFFile('QPDF-367-0.pdf'))), 0);
assert.equal((await getPDFSignatureCount(await getRealPDFFile('qual-sig-simple.pdf'))), 1);
assert.equal((await getPDFSignatureCount(await getRealPDFFile('qual-sig-tugraz-multiple.pdf'))), 2);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment