[cups] Can't detect file type / Not a PDF file

Henrik Morsing henrik at morsing.cc
Thu May 2 07:59:40 PDT 2019


On Thu, May 02, 2019 at 04:36:18PM +0200, Till Kamppeter wrote:
>
>The parse_doc_type() in the filter/gstoraster.c in cups-filters checks 
>through the whole file whether a line starts with "%!" or "%PDF". If 
>such a line gets found the file is considered PostScript or PDF 
>respectively. So a PJL header does not prevent identification of the 
>file.
>

Hi,

I don't really do C++ programming but:

parse_doc_type(FILE *fp)
{
  char buf[5];

  /* get the first few bytes of the file */
  rewind(fp);
/* skip until PDF/PS start header */
 while (fgets(buf,sizeof(buf),fp) != 0) {
   if (strncmp(buf,"%PDF",4) == 0) return GS_DOC_TYPE_PDF;
   if (strncmp(buf,"%!",2) == 0) return GS_DOC_TYPE_PS;
  }
  return GS_DOC_TYPE_UNKNOWN;
}


the comment alone says "get the first few bytes of the file"? And buf[5], is that five bytes? In which case that wouldn't get to the %!.

Thanks
Henrik


More information about the cups mailing list