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

Re: Fake PDF


On 2/24/26 11:11 AM, Gianluigi 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.

Regards
Gianluigi

Willy explained what I mean by shelling out to the `file` command. I'd like to explain hopefully a little better about what DesktopMime.FromFile() does.

That method queries the system mime type file at "/usr/share/mime/globs2" basically using it as a look-up table. On my system, line 139 in that file is "50:application/pdf:*.pdf". So according to that file, all files with a ".pdf" extension are of type "application/pdf". It is really stupid as it relies on the file extension as opposed to the file contents.

Simplified, DesktopMime.FromFile() looks up the file extension in "/usr/share/mime/globs2", finds that it is of type "application/pdf", and returns that text. BTW, the Stat object created by the Stat() function will also falsely return "application/pdf" for that fake PDF file.

The `file` command, on the other hand, will actually look at the header content of the file to determine its actual type.

I hope that helps explain it better.


--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


Follow-Ups:
Re: Fake PDFgbWilly <gbWilly@xxxxxxxxxxxxxx>
References:
Fake PDFGianluigi <gradobag@xxxxxxxxxxx>
Re: Fake PDFLee <t.lee.davidson@xxxxxxxxx>
Re: Fake PDFGianluigi <gradobag@xxxxxxxxxxx>