[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fake PDF


On Tuesday, February 24th, 2026 at 17:11, Gianluigi <gradobag@xxxxxxxxxxx> wrote:

> Il 24/02/26 16:49, Lee ha scritto:
> > Well, I'm not Benoît, but I can tell you that it is not a mistake on
> > your part and that the Mime type IS working.
> >
> > The code of DesktopMime.FromFile() tries first to determine the MIME
> > type by querying the MIME database file (/usr/share/mime/globs2) which
> > lists the MIME type based on the file's extension. On my system, line
> > 139 of that file indicates that "*.pdf" files are of type "application/
> > pdf".
> >
> > It can be fooled if the extension is not correct. If you need better
> > mime type determination, you can shell out to `file`.
> 
> Hi Lee,
> 
> I'm probably not understanding what you're trying to say. I tried using
> BaseName, but I get an error and don't get "File type: Plain Text
> Document (text/plain)" like I get when opening the same file with Mint's
> document viewer.
> 

Here is what Lee means with file

Open a terminal and type:
file --mime-type filename

Example (for a file on your desktop):
cd Desktop
file --mime-type Screen.png
This will return:
Screen.png: image/png

DesktopMime.FromFile() in theory should return the same. To my knowledge, file extensions should mean nothing on Linux, Mime type is relevant.
But what Lee says is that the Mime type database looks at extensions and thus never returns the true format of a file as extensions can be changed, that is a filename change but doesn't change the format.

If I change a .pdf to .txt, DesktopMime.FromFile() returns text/plain
file --mime-type returns application/pdf (see attached screen)

This latter is what I expect on a Linux system, the TRUE Mime-type, so DesktopMime.FromFile is useless as it looks at extensions and not the actual Mime type, so you risk to get a FAKE MIME-type based on extensions (that should mean nothing in linux). Are there M$ developers involved in the xdg-mime project, or what? Or is xdg-mime used on M$ Widows as well, or what is going on here?

In 2012 I wrote a function using file to determine the mime-type and had it in my library for use in applications. I have used it ever since where I needed it and it always returned me the TRUE MIME type.

With the writing of the GambOS guides, I decided to use DesktopMime.FromFile() instead (I don't believe it was around in 2012 since I had to code my own solution), and so I dropped my old function. Now, thanks to Gianluigi, I discover that I better drop DesktopMime.FromFile completely and revert back to my old function based on the command 'file'.

This DesktopMime.FromFile() test is used to see if a file is a pdf or not when opening GambOS PdfViewer, so kind of important that the TRUE Mime type is retrieved.

If I have a real pdf and change the extension, it will not be seen as pdf anymore and thus not open (although file says it is of type application/pdf correctly as the format of the file didn't change, just it's name). If I have a real plain text file and change the extension to pdf, GambOS PdfViewer will not prevent opening it as DektopMime says its an application/pfd although it's format is plain/text in reality. 

So, DesktopMime can not be trusted to tell us the real format of a file, where the command 'file' can. In short, bye bye DesktopMime.FromFile, totally useless IMHO.

gbWilly

Attachment: post.png
Description: PNG image


References:
Fake PDFGianluigi <gradobag@xxxxxxxxxxx>
Re: Fake PDFLee <t.lee.davidson@xxxxxxxxx>
Re: Fake PDFGianluigi <gradobag@xxxxxxxxxxx>