PERFORCE change 219763 for review
Brooks Davis
brooks at FreeBSD.org
Mon Nov 12 18:58:58 UTC 2012
http://p4web.freebsd.org/@@219763?ac=10
Change 219763 by brooks at brooks_ecr_current on 2012/11/12 18:58:51
Split the common PNG decoding bits out from the sandbox
creation. Build the capsicum helper static.
Affected files ...
.. //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/Makefile#3 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/decode_png.c#1 add
.. //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/pngbox.c#3 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng/Makefile#3 edit
Differences ...
==== //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/Makefile#3 (text+ko) ====
@@ -7,7 +7,7 @@
LIB= imagebox
SHLIB_MAJOR= 1
-SRCS= pngbox.c
+SRCS= decode_png.c pngbox.c
INCS= imagebox.h
==== //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/pngbox.c#3 (text+ko) ====
@@ -47,9 +47,6 @@
#include "imagebox.h"
#include "iboxpriv.h"
-static void read_row_callback(png_structp, png_uint_32, int);
-static void read_png_from_fd(png_structp, png_bytep, png_size_t);
-
struct pthr_decode_private
{
pthread_t pthr;
@@ -60,84 +57,6 @@
pid_t pid;
};
-void
-decode_png(struct ibox_decode_state *ids)
-{
- int bit_depth, color_type, interlace_type;
- png_uint_32 r, width, height;
- png_structp png_ptr = NULL;
- png_infop info_ptr = NULL;
- png_infop end_info = NULL;
- png_bytep *rows = NULL;
-
- if ((png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
- NULL, NULL, NULL)) == NULL) {
- ids->is->error = 1;
- goto error;
- }
- if ((info_ptr = png_create_info_struct(png_ptr)) == NULL) {
- ids->is->error = 1;
- goto error;
- }
- if ((end_info = png_create_info_struct(png_ptr)) == NULL) {
- ids->is->error = 1;
- goto error;
- }
-
- if (setjmp(png_jmpbuf(png_ptr))) {
- ids->is->error = 1;
- goto error;
- }
-
-#if 0
- /* XXX Insert back door function here */
- png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
- read_chunk_callback);
-#endif
-
- png_set_read_status_fn(png_ptr, read_row_callback);
-
- /*
- * Reject the image if the parser finds a different size than
- * our manual parsing did.
- */
-#if 0
- png_set_user_limits(png_ptr, width, height);
-#endif
-
- png_set_read_fn(png_ptr, ids, read_png_from_fd);
-
- png_read_info(png_ptr, info_ptr);
-
- png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
- &color_type, &interlace_type, NULL, NULL);
-
- if (width != ids->is->width || height != ids->is->height) {
- ids->is->error = 1;
- goto error;
- }
-
- png_set_gray_to_rgb(png_ptr);
- png_set_bgr(png_ptr);
- png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
- ids->is->passes_remaining = png_set_interlace_handling(png_ptr);
- png_read_update_info(png_ptr, info_ptr);
-
- if ((rows = malloc(height*sizeof(png_bytep))) == NULL)
- png_error(png_ptr, "failed to malloc row array");
- for (r = 0; r < height; r++)
- rows[r] = (png_bytep)(ids->buffer + (width * r));
-
- png_read_rows(png_ptr, rows, NULL, height);
-
- png_read_end(png_ptr, end_info);
-
-error:
- png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
- close(ids->fd);
- free(rows);
-}
-
static void *
pthr_decode_png(void *arg)
{
@@ -394,27 +313,3 @@
break;
}
}
-
-static void
-read_row_callback(png_structp png_ptr, png_uint_32 row, int pass __unused)
-{
- struct ibox_decode_state *ids;
-
- ids = png_get_io_ptr(png_ptr);
- if (ids->is->valid_rows < row)
- ids->is->valid_rows = row;
- if (row == ids->is->height)
- ids->is->passes_remaining--;
-}
-
-static void
-read_png_from_fd(png_structp png_ptr, png_bytep data, png_size_t length)
-{
- struct ibox_decode_state *ids;
- ssize_t rlen;
-
- ids = png_get_io_ptr(png_ptr);
- rlen = read(ids->fd, data, length);
- if (rlen < 0 || (png_size_t)rlen != length)
- png_error(png_ptr, "read error");
-}
==== //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng/Makefile#3 (text+ko) ====
@@ -4,8 +4,10 @@
PROG= readpng
+NO_SHARED= yes
+
.PATH: ${.CURDIR}/../../../ctsrd-lib/libimagebox
-SRCS= readpng.c pngbox.c
+SRCS= readpng.c decode_png.c
MAN=
@@ -14,12 +16,12 @@
CFLAGS+= -I${.CURDIR}/../../../ctsrd-lib/libimagebox
.if ${MACHINE_ARCH} == "amd64"
CFLAGS+= -I/usr/local/include
-LDFLAGS+= -L/usr/local/lib
+LDADD+= -L/usr/local/lib -lpng
.else
CFLAGS+= -I${.CURDIR}/../../libvuln_png
-LDFLAGS+= -lvuln_png
+LDADD+= -lvuln_png
.endif
-LDFLAGS+= -lpthread -lz -lm
+LDADD+= -lz -lm
WARNS= 6
More information about the p4-projects
mailing list