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!
This could cause problems with loops, if fz_write_printf itself were to throw an exception.
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?
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.
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.
*** Bug 697973 has been marked as a duplicate of this bug. ***