Skip to content

Commit f34e9f7

Browse files
authored
Fix detecting small PDF file (#728)
1 parent c442a9e commit f34e9f7

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

core.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -726,17 +726,19 @@ export class FileTypeParser {
726726

727727
if (this.checkString('%PDF')) {
728728
try {
729-
await tokenizer.ignore(1350);
730-
const maxBufferSize = 10 * 1024 * 1024;
731-
const buffer = new Uint8Array(Math.min(maxBufferSize, tokenizer.fileInfo.size));
732-
await tokenizer.readBuffer(buffer, {mayBeLess: true});
733-
734-
// Check if this is an Adobe Illustrator file
735-
if (includes(buffer, new TextEncoder().encode('AIPrivateData'))) {
736-
return {
737-
ext: 'ai',
738-
mime: 'application/postscript',
739-
};
729+
const skipBytes = 1350;
730+
if (skipBytes === await tokenizer.ignore(skipBytes)) {
731+
const maxBufferSize = 10 * 1024 * 1024;
732+
const buffer = new Uint8Array(Math.min(maxBufferSize, tokenizer.fileInfo.size - skipBytes));
733+
await tokenizer.readBuffer(buffer, {mayBeLess: true});
734+
735+
// Check if this is an Adobe Illustrator file
736+
if (includes(buffer, new TextEncoder().encode('AIPrivateData'))) {
737+
return {
738+
ext: 'ai',
739+
mime: 'application/postscript',
740+
};
741+
}
740742
}
741743
} catch (error) {
742744
// Swallow end of stream error if file is too small for the Adobe AI check

0 commit comments

Comments
 (0)