[cairo-commit] 3 commits - src/cairo-pdf-interchange.c src/cairo-pdf-surface.c src/cairo-pdf-surface-private.h test/create-for-stream.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Jul 24 08:08:46 UTC 2021


 src/cairo-pdf-interchange.c     |    4 +---
 src/cairo-pdf-surface-private.h |    2 +-
 src/cairo-pdf-surface.c         |    4 +++-
 test/create-for-stream.c        |   26 +++++++++++++++++++++++++-
 4 files changed, 30 insertions(+), 6 deletions(-)

New commits:
commit d12e55672caec22a6b93468914c82f1a90293db7
Merge: b408352d4 e689e6700
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jul 24 08:08:44 2021 +0000

    Merge branch 'pdf-stdio-write-errors' into 'master'
    
    pdf: Properly pass on stdio write errors
    
    See merge request cairo/cairo!210

commit e689e670049b26be8c6bff69f3de372bddb8d856
Author: Uli Schlachter <psychon at znc.in>
Date:   Fri Jul 23 17:32:39 2021 +0200

    Fix build on windows
    
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/test/create-for-stream.c b/test/create-for-stream.c
index 3e7577a6a..06f2db2b0 100644
--- a/test/create-for-stream.c
+++ b/test/create-for-stream.c
@@ -28,7 +28,10 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+
+#ifndef _WIN32
 #include <unistd.h>
+#endif
 
 #if CAIRO_HAS_PS_SURFACE
 #include <cairo-ps.h>
@@ -172,6 +175,7 @@ test_surface (const cairo_test_context_t *ctx,
     }
 
     /* test propagation of file errors - for now this is unix-only */
+#ifndef _WIN32
     if (access("/dev/full", W_OK) == 0) {
 	surface = file_constructor ("/dev/full", WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
 	cairo_surface_finish (surface);
@@ -188,6 +192,7 @@ test_surface (const cairo_test_context_t *ctx,
 	cairo_test_log (ctx,
 			"/dev/full does not exist; skipping write test.\n");
     }
+#endif
 
     /* construct the real surface */
     wc.ctx = ctx;
commit 2fbd53a6b33a90a08ef6eda9e5f88e8fb3b97c1e
Author: Uli Schlachter <psychon at znc.in>
Date:   Fri Jul 23 17:22:16 2021 +0200

    pdf: Properly pass on stdio write errors
    
    cairo-pdf was silently ignoring write errors in
    _cairo_pdf_surface_finish(). Any write errors that happened here ended
    up setting a "status" variable, but the value in this variable was then
    unused.
    
    This commit fixes this bug by passing this error on to the caller.
    
    Additionally, this also adds a test case for this behaviour based on
    writing to /dev/full. This file is non-standard and thus the test first
    checks that this file exists and is writable before trying to write to
    it.
    
    This bug was found based on a report from Knut Petersen [0].
    
    [0]: https://lists.cairographics.org/archives/cairo/2021-July/029281.html
    
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/src/cairo-pdf-interchange.c b/src/cairo-pdf-interchange.c
index 5cc10eb0b..ad4072e63 100644
--- a/src/cairo-pdf-interchange.c
+++ b/src/cairo-pdf-interchange.c
@@ -1515,7 +1515,7 @@ _cairo_pdf_interchange_free_outlines (cairo_pdf_surface_t *surface)
     _cairo_array_fini (&ic->outline);
 }
 
-cairo_int_status_t
+void
 _cairo_pdf_interchange_fini (cairo_pdf_surface_t *surface)
 {
     cairo_pdf_interchange_t *ic = &surface->interchange;
@@ -1539,8 +1539,6 @@ _cairo_pdf_interchange_fini (cairo_pdf_surface_t *surface)
     free (ic->docinfo.creator);
     free (ic->docinfo.create_date);
     free (ic->docinfo.mod_date);
-
-    return CAIRO_STATUS_SUCCESS;
 }
 
 cairo_int_status_t
diff --git a/src/cairo-pdf-surface-private.h b/src/cairo-pdf-surface-private.h
index 3793332ce..49776b90f 100644
--- a/src/cairo-pdf-surface-private.h
+++ b/src/cairo-pdf-surface-private.h
@@ -355,7 +355,7 @@ _cairo_utf8_to_pdf_string (const char *utf8, char **str_out);
 cairo_private cairo_int_status_t
 _cairo_pdf_interchange_init (cairo_pdf_surface_t *surface);
 
-cairo_private cairo_int_status_t
+cairo_private void
 _cairo_pdf_interchange_fini (cairo_pdf_surface_t *surface);
 
 cairo_private cairo_int_status_t
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index b033fdf07..f2463a8c3 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -2329,7 +2329,9 @@ _cairo_pdf_surface_finish (void *abstract_surface)
 
     _cairo_surface_clipper_reset (&surface->clipper);
 
-    return _cairo_pdf_interchange_fini (surface);
+    _cairo_pdf_interchange_fini (surface);
+
+    return status;
 }
 
 static cairo_int_status_t
diff --git a/test/create-for-stream.c b/test/create-for-stream.c
index af1632f14..3e7577a6a 100644
--- a/test/create-for-stream.c
+++ b/test/create-for-stream.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <unistd.h>
 
 #if CAIRO_HAS_PS_SURFACE
 #include <cairo-ps.h>
@@ -165,11 +166,29 @@ test_surface (const cairo_test_context_t *ctx,
 
     if (status != CAIRO_STATUS_WRITE_ERROR) {
 	cairo_test_log (ctx,
-			"%s: Error: expected \"write error\", but received \"%s\".\n",
+			"%s: Error: expected \"write error\" from bad_write(), but received \"%s\".\n",
 			backend, cairo_status_to_string (status));
 	return CAIRO_TEST_FAILURE;
     }
 
+    /* test propagation of file errors - for now this is unix-only */
+    if (access("/dev/full", W_OK) == 0) {
+	surface = file_constructor ("/dev/full", WIDTH_IN_POINTS, HEIGHT_IN_POINTS);
+	cairo_surface_finish (surface);
+	status = cairo_surface_status (surface);
+	cairo_surface_destroy (surface);
+
+	if (status != CAIRO_STATUS_WRITE_ERROR) {
+	    cairo_test_log (ctx,
+			    "%s: Error: expected \"write error\" from /dev/full, but received \"%s\".\n",
+			    backend, cairo_status_to_string (status));
+	    return CAIRO_TEST_FAILURE;
+	}
+    } else {
+	cairo_test_log (ctx,
+			"/dev/full does not exist; skipping write test.\n");
+    }
+
     /* construct the real surface */
     wc.ctx = ctx;
     wc.status = CAIRO_TEST_SUCCESS;


More information about the cairo-commit mailing list