Bug 2359 - Text file recognized as a bitmap
Summary: Text file recognized as a bitmap
Status: RESOLVED FIXED
Alias: None
Product: shared-mime-info
Classification: Unclassified
Component: freedesktop.org.xml (show other bugs)
Version: unspecified
Hardware: x86 (IA32) Linux (All)
: high normal
Assignee: Jonathan Blandford
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-23 09:03 UTC by Vincent Untz
Modified: 2010-06-26 08:25 UTC (History)
4 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Vincent Untz 2005-01-23 09:03:26 UTC
I have a text file that begins with "TP1" (you can create one with just these
three characters). When double-clicking on it in nautilus, it tells me that the
filename suggests it's a text file but the file content suggests it's a portable
bitmap file.

The "file" command recognizes the file as ASCII text.
Comment 1 Christophe Fergeau 2005-04-16 13:07:29 UTC
So, this was indeed a mismatch, I committed a fix to xdgmime CVS, but now it
will identify files beginning with P1 as portable bitmap files, I guess you
won't consider this bug as fixed in a satisfactory way :)
Comment 2 Bastien Nocera 2006-07-09 03:43:45 UTC
$ echo "P1" > foo
$ file foo
foo: Netpbm PBM image text

Should we leave this bug opened?
Comment 3 Benjamin Close 2008-01-11 02:36:55 UTC
Bugzilla Upgrade Mass Bug Change

NEEDSINFO state was removed in Bugzilla 3.x, reopening any bugs previously listed as NEEDSINFO.

  - benjsc
    fd.o Wrangler
Comment 4 Daniel Leidert 2008-02-05 14:10:57 UTC
(In reply to comment #0)
> I have a text file that begins with "TP1" (you can create one with just these
> three characters). When double-clicking on it in nautilus, it tells me that the
> filename suggests it's a text file but the file content suggests it's a portable
> bitmap file.

Hm. ATM in fast detection its detected as application/octet-stream by gnomevfs-info. If it would be detected as text/plain, then gnomevfs shouldn't detect it as image/x-portable-bitmap.

I'm not sure if the problem can be solved in the shared-mime-info database. IMO there are two alternatives: 1) remove the magic from image/x-portable-bitmap (no conflicting global pattern) or b) forward this to the upstream of gnomevfs and kdemime and check, if some better heuristics between text/plain and application/octet-stream can solve this problem.

Comment 5 Daniel Leidert 2008-02-05 14:29:27 UTC
Hm. After reading some more about the formats, it should also be possible to extend the graphics a bit to be

P1\x0a# (offset: 0)

so the magic includes the (possible) comment in line 2, although this comment is not required. But it is less generic than just searching for P1..7.
Comment 6 Sense Hofstede 2008-02-28 09:15:17 UTC
This bug has also been reported in launchpad for PBM images by Tom Womack: https://bugs.edge.launchpad.net/ubuntu/+source/shared-mime-info/+bug/99736
He said: 
"I have a text file which begins 'P13438 = 2 * 3 * 7 * 1047137401 * 8868717860281682366053088136263931781236052676953 * 37740643638981149828904962487908210028313437770048087043525652181' - it's a list of factorizations of partition numbers.

For some reason nautilus thinks this is a PBM image, and won't by default open it with gedit.

I think that files which claim to be text files should be opened with the text editor whether or not nautilus thinks they are text files."
Comment 7 Bastien Nocera 2008-06-11 10:25:43 UTC
(In reply to comment #5)
> Hm. After reading some more about the formats, it should also be possible to
> extend the graphics a bit to be
> 
> P1\x0a# (offset: 0)
> 
> so the magic includes the (possible) comment in line 2, although this comment
> is not required. But it is less generic than just searching for P1..7.

Seems like the best option. A magic of 2 characters is just too short...

* freedesktop.org.xml.in: Tighten the magic for PBM,
PPM and PGM types, so as to avoid false positives
(Closes: #2359)
* tests/list:
* tests/test.pbm: Add a pbm test file
Comment 8 Nuno J. Silva 2010-06-26 08:25:12 UTC
Some image viewers, which rely on gtk+ to show images, are unable to show portable anymaps. gtk+ seems to rely on freedesktop.org.xml for file type detection, which fails for some anymaps.

Removing the lines about # solves this, and here "man 5 ppm" does not say a comment is needed (although it can exist).


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.