Bug 701263 - source/fitz/error.c: use fz_write_printf instead of fprintf
Summary: source/fitz/error.c: use fz_write_printf instead of fprintf
Status: RESOLVED FIXED
Alias: None
Product: MuPDF
Classification: Unclassified
Component: fitz (show other bugs)
Version: unspecified
Hardware: PC Linux
: P4 normal
Assignee: MuPDF bugs
URL:
Keywords:
: 697973 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-06-23 06:55 UTC by josch
Modified: 2021-02-04 12:22 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
source/fitz/error.c: use fz_write_printf instead of fprintf (1.90 KB, patch)
2019-06-23 06:55 UTC, josch
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description josch 2019-06-23 06:55:09 UTC
Created attachment 17766 [details]
source/fitz/error.c: use fz_write_printf instead of fprintf

The PyMuPDF Python binding for mupdf (https://github.com/pymupdf/PyMuPDF) currently uses attached patch to prevent output on stderr. Please consider applying this patch so that PyMuPDF does not have to carry it anymore.

I'm currently packaging PyMuPDF for Debian and this would make our life easier. Thanks!
Comment 1 Tor Andersson 2019-06-24 09:14:54 UTC
This could cause problems with loops, if fz_write_printf itself were to throw an exception.
Comment 2 josch 2019-06-24 10:56:28 UTC
fz_vsnprintf is already used in error.c and as far as I can see uses the same code as fz_write_printf, namely fz_format_string. How does the current code guard against loops created by fz_vsnprintf throwing an error?
Comment 3 Tor Andersson 2019-06-24 11:56:01 UTC
fz_vsnprintf is safe (an evidenced by the fact that it doesn't take a fz_context). Writing the resulting string to a fz_output object could throw in fz_write_byte calleb dy the fz_write_emit callback used by fz_write_printf.

I have added two functions to provide custom error/warning callbacks which should provide a safer mechanism for redirecting error messages.

commit 6d28dcdedc68b3303a519fcf92536bfcfaa4f15f
Author: Tor Andersson <tor.andersson@artifex.com>
Date:   Mon Jun 24 11:37:42 2019 +0200

    Bug 701263: Provide error/warning callback methods.
    
    In order to override the default behaviour of printing to stdout, we
    provide user callbacks for emitting error and warning messages.
    
    The default implementation prints to stderr on all platforms.
    On Windows, it also uses OutputDebugString in debug builds.
    On Android, it also uses the Android logging mechanisms.
Comment 4 Tor Andersson 2021-02-04 12:22:16 UTC
commit 6d28dcdedc68b3303a519fcf92536bfcfaa4f15f
Author: Tor Andersson <tor.andersson@artifex.com>
Date:   Mon Jun 24 11:37:42 2019 +0200

    Bug 701263: Provide error/warning callback methods.
    
    In order to override the default behaviour of printing to stdout, we
    provide user callbacks for emitting error and warning messages.
    
    The default implementation prints to stderr on all platforms.
    On Windows, it also uses OutputDebugString in debug builds.
    On Android, it also uses the Android logging mechanisms.
Comment 5 Tor Andersson 2021-02-04 12:22:39 UTC
*** Bug 697973 has been marked as a duplicate of this bug. ***