Reinhard Kotucha writes:
> Olaf Weber <[EMAIL PROTECTED]> writes:

>> Does the following change fix this?

> Yes, thank you.  But I have to provide the stream object number,
> though the usage message says that it's optional.

[...]

> I suppose that it should be optional. If it is omitted, pdftosrc
> should behave as if stream-object-number is 0.  In this case 
> it should look for /SourceFile.  But srcStream.isStream("SourceFile")
> is always 0. (pdftosrc.cc, line 85)

The reason it is always 0 is becayse there is no SourceObject in the
Catalog.  To put the SourceObject there, use \pdfcatalog instead of
\immediate\pdfcatalog (it's not entirely clear to why the latter
doesn't work).  And then you need to make sure there's something in
the pdf at all.  So a corrected example would be:

\pdfcompresslevel=0
\immediate\pdfobj stream
  attr {/Type /SourceFile /SourceName (\jobname.src)}
  file {\jobname.tex}
\pdfcatalog{/SourceObject \the\pdflastobj\space 0 R}
Hello world!
\bye


At that point you'll also discover that pdftosrc writes its output to
a garbage file name, which turns out to be a use-after-free problem.
The full patch now becomes:

--- pdftosrc.cc-        2002-12-20 19:47:27.000000000 +0100
+++ pdftosrc.cc 2003-01-26 14:58:25.000000000 +0100
@@ -61,7 +61,6 @@
     }
     fileName = new GString(argv[1]);
     globalParams = new GlobalParams("");
-    xref = NULL;
     doc = new PDFDoc(fileName);
     if (!doc->isOk()) {
         fprintf(stderr, "Invalid PDF file\n");
@@ -72,6 +71,7 @@
         if (argc >= 4)
             objgen = atoi(argv[3]);
     }
+    xref = doc->getXRef();
     catalogDict.initNull();
     xref->getCatalog(&catalogDict);
     if (!catalogDict.isDict("Catalog")) {
@@ -92,7 +92,8 @@
             exit(1);
         }
         outname = srcName.getString()->getCString();
-        srcName.free();
+        // We cannot free srcName, as objname shares its string.
+        // srcName.free();
     }
     else {
         xref->fetch(objnum, objgen, &srcStream);
@@ -110,7 +111,7 @@
         outname = buf;
     }
     if (!(outfile = fopen(outname, "wb"))) {
-        fprintf(stderr, "Cannot open file for writting\n");
+        fprintf(stderr, "Cannot open file \"%s\" for writing\n", outname);
         exit(1);
     }
     s = srcStream.getStream();



-- 
Olaf Weber

               (This space left blank for technical reasons.)

Reply via email to