Bug 50111 - kghostview misdetects mimetype of ps files when they have .pdf extension
Summary: kghostview misdetects mimetype of ps files when they have .pdf extension
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: unspecified All
: NOR normal
Target Milestone: ---
Assignee: Wilco Greven
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-03 16:42 UTC by mark
Modified: 2003-03-17 12:12 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
simple test case for bug (4.83 KB, application/pdf)
2002-11-05 04:46 UTC, mark
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mark 2002-11-03 16:42:10 UTC
Version:           0.13.2 (using KDE KDE 3.0.8)
Installed from:    Unlisted Binary Package
OS:          FreeBSD

Hello,

This morning I created a PDF file by using the OpenOffice 1.0.1 "Print to File" feature". The resulting file would not open in Kghostview. Here's the output in the terminal:

mark@asana> kghostview 5_scenerios_for_longterm.pdf
kio (KDirWatch): Can't use FAM (fam daemon not running?)
kio (KDirWatch): Available methods: Stat
kghostview (kdegraphics): KGVConfigDialog::readSettings
kghostview (kdegraphics): KPSWidget::setupWidget()
kparts: MainWindow::createGUI, part=0x80e6000 KGVPart kgvpart
kghostview (kdegraphics): KGVRun::foundMimeType( application/pdf )
kghostview (kdegraphics): KGVPart::slotMimetype: type=application/pdf
kghostview (kdegraphics): KGVMiniWidget::openFile
kghostview (kdegraphics): Pdf2dsc: started
kghostview (kdegraphics): Pdf2dsc: process exited
kghostview (kdegraphics): KGVMiniWidget::openPDFFileContinue
#######
The same file opens fine with "gv". 

Thanks!  -mark
Comment 1 Moritz Moeller-Herrmann 2002-11-04 18:40:41 UTC
Please add such a file as attachment.  
Comment 2 mark 2002-11-05 04:46:21 UTC
Created attachment 371 [details]
simple test case for bug
Comment 3 Luís Pedro Coelho 2002-11-16 17:31:22 UTC
I just checked the file and it is a postscript file! 
 
It doesn't open if you try to open it as PDF because, of course, PDF parsing fails. 
Apparently gv just ignores the extension uses magic to determine the real file type. 
 
Don't know how this case should be handled by kghostview, though. 
Comment 4 mark 2002-11-25 01:28:01 UTC
I confirmed tonight that when I use the OpenOffice "print to PDF" feature, it   
is producing a file that is identical in size to the one produced by the   
"print to Postscript" feature-- as noted above.  This is a bug in OpenOffice.   
Could KGhostview be updated to handle this more gracefully, though? It looks  
like PDF files always start like this:  
%PDF  
and  Postscript files start like this: 
%!PS 
 
Perhaps KGhostview could be updated to check for that? Even if it just emits 
an better error like "file extension was .pdf, but appears to contain a 
Postscript file. I don't think you would even need to perform this check all 
the time-- it could be a last resort when the program is about to fail as it 
did above.  
Comment 5 Moritz Moeller-Herrmann 2002-12-23 00:44:12 UTC
If you rename a postscript file to a name ending in .pdf, kghostview fails to open it. 
 
This is a bug, as kghostview should never rely on the file name! 
Comment 6 Luís Pedro Coelho 2003-03-14 12:18:51 UTC
I think this should be classified as a kio bug because that's where kghostview gets 
the mimetype guessing from. 
Comment 7 Stephan Kulow 2003-03-17 12:12:00 UTC
Subject: kdelibs/mimetypes/application

CVS commit by coolo: 

kio magic can recognize both pretty correct, so don't screw it up when
using patterns (again it would be nice to have a way to specifiy that
the pattern should only be used when no magic can be used)
CCMAIL: 50111-close@bugs.kde.org


  M +0 -1      pdf.desktop   1.206
  M +0 -1      postscript.desktop   1.196


--- kdelibs/mimetypes/application/pdf.desktop  #1.205:1.206
@@ -4,5 +4,4 @@
 MimeType=application/pdf
 Icon=pdf
-Patterns=*.pdf;*.PDF;
 Comment=PDF Document
 Comment[af]=Pdf Dokument

--- kdelibs/mimetypes/application/postscript.desktop  #1.195:1.196
@@ -4,5 +4,4 @@
 MimeType=application/postscript
 Icon=postscript
-Patterns=*.ps;*.PS;
 Comment=PostScript Document
 Comment[af]=Postscript Dokument


Comment 8 Stephan Kulow 2003-03-20 08:54:25 UTC
Subject: Re: kdelibs/mimetypes/application

On Wednesday 19 March 2003 22:55, David Faure wrote:
> On Monday 17 March 2003 12:11, Stephan Kulow wrote:
> > CVS commit by coolo:
> >
> > kio magic can recognize both pretty correct, so don't screw it up when
> > using patterns (again it would be nice to have a way to specifiy that
> > the pattern should only be used when no magic can be used)
> 
> Interesting......
> 1) see untested patch below, if we want to go that way
> 2) the xdg-defined mimetype future-standard defines the same order as the one
> we had up to now: extensions first, magic as fallback.
>    http://www.ecs.soton.ac.uk/~tal00r/info.html#id2797567
> And I did agree with the reasoning behind it: it's easier for the user to
> change the extension if the filetype isn't recognized correctly, than to
> fix things if the magic goes wrong. The problem with relying on the magic is
> that the magic isn't always correct!
> Hmm, ok, I guess it's much more reliable for image formats and PS/PDF
> than for e.g. C++ and other text-based stuff.

I'm very much aware of your reasonings and would have decided the same. But fact
is people don't stop naming their postscript files *.pdf for whatever reason :)

And as long as we can use magic and we're pretty sure the magic works most often
reliable for that file type, we should flag that somehow. I remember days when the
file magic returned a percentage value of what it thought how correct it's guess was.
I have no idea how it did that, but if that could work, it would be best. Second best is
your patch I guess :)

Greetings, Stephan

Comment 9 Allan Sandfeld 2004-02-12 16:52:41 UTC
CVS commit by carewolf: 

We can use patterns, but we dont entirely trust them though.
If noone complains I will backport to KDE_3_2_BRANCH and close 75031.

CCMAIL: 75031@bugs.kde.org
CCMAIL: 50111@bugs.kde.org


  M +2 -0      pdf.desktop   1.227
  M +1 -0      postscript.desktop   1.213


--- kdelibs/mimetypes/application/pdf.desktop  #1.226:1.227
@@ -4,4 +4,6 @@
 MimeType=application/pdf
 Icon=pdf
+Patterns=*.pdf;*.PDF;
+X-KDE-PatternsAccuracy=90
 Comment=PDF Document
 Comment[af]=Pdf Dokument

--- kdelibs/mimetypes/application/postscript.desktop  #1.212:1.213
@@ -5,4 +5,5 @@
 Icon=postscript
 Patterns=*.ps;*.PS;
+X-KDE-PatternsAccuracy=95
 Comment=PostScript Document
 Comment[af]=Postscript Dokument