Skip to content

[TIKA-4098] Detection fails on PDF with garbage before header #1231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,8 @@
<magic priority="20">
<!-- Low priority match for %PDF-#.# near the start of the file -->
<!-- Can trigger false positives, so set the priority rather low here -->
<match value="%PDF-1." type="string" offset="1:512"/>
<match value="%PDF-2." type="string" offset="1:512"/>
<match value="%PDF-1." type="string" offset="1:768"/>
<match value="%PDF-2." type="string" offset="1:768"/>
</magic>
<glob pattern="*.pdf"/>
</mime-type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,15 @@ public void testFontNameExtraction() throws Exception {
assertContains("ABCDEE+Calibri", r.metadata.get(Font.FONT_NAME));
}

@Test
public void testGarbageBeforeHeader() throws Exception {
Metadata metadata = getXML("testPDF_garbageBeforeHeader.pdf").metadata;
assertEquals("application/pdf", metadata.get(Metadata.CONTENT_TYPE));
}

@Test
public void testPdfParsingMetadataOnly() throws Exception {

Metadata metadata = getXML("testPDF.pdf").metadata;
assertEquals("application/pdf", metadata.get(Metadata.CONTENT_TYPE));
assertEquals("Bertrand Delacr\u00e9taz", metadata.get(TikaCoreProperties.CREATOR));
Expand Down
Binary file not shown.