I am creating a secure document portal for a client. One of the things that they are worried about is having someone upload a document with a virus. One solution that might work is to enforce that they only upload pdf files.

My question is two fold:

  1. Most importantly, is a pdf document virus proof?
  2. How can you determine in a *nix environment that a file is a pdf, besides just looking at the extension.

migrated from stackoverflow.com May 17 '10 at 19:48

This question came from our site for professional and enthusiast programmers.

  • Welcome to Stack Overflow! However this is more of a SuperUser.com question (sister site aimed at non-programming questions). – Tom Kidd May 17 '10 at 19:44
  • For #2, are you talking about code determining this, or a user? IE, are you wondering how to write something to determine if the file is a PDF (good for Stack Overflow), or how to use a program or other utility to do the determination (good for SuperUser)? – Beska May 17 '10 at 19:47
  • The simple answer is: NO. There is no such thing as utterly virus-proof. Any door can be broken, any lock picked by someone who has enough time, money and/or effort to throw at it. – eidylon May 17 '10 at 20:40

PDF's (and its readers) are certainly not immune to attacks (one example here; googling for pdf vulnerability or pdf arbitrary code execution should yield more).

In a *nix environment checking the file contents with file could be a start.

  • Lately with Adobe's Reader it could be called the Penetratable Document Format (not sure about Foxit). Reader has had problems like buffer overflows and JavaScript being enabled by default and they are releasing patches regularly now. – Bratch May 17 '10 at 22:59

If I remember, Unix/Linux has a command called "file" that will tell you what type of file it is.

  1. Theoretically, a PDF cannot contain any executable code; however, specially crafted PDF files can possibly get the viewer to run native code if there is a vulnerability in the viewer. Adobe (Acrobat) Reader, for example is notorious for buffer overflow issues. Each viewer will have its own set of vulnerabilities, and the most important thing is to keep the viewer updated.

  2. file myfile.pdf will print something containing PDF document.


PDFs are not inherently virus-proof. Like anything, if you know the vulnerabilities in a common reader for the file, you can put something in the file to exploit that, which can then download the main payload. Images (heck, image files on Mac have been infected), pdf, whatever, can be "infected" somehow, and lead to a virus.

On the second note, as somebody else said, there is a file command on Linux, that looks at the actual data in the file to tell you the filetype.


There was an article recently about PDFs being susceptible to viruses from any viewer; searching for the link.


  • Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change. – DavidPostill Sep 20 '17 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.