Date: Thu, 15 Nov 2012 06:39:01 GMT From: Brooks Davis <brooks@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 219792 for review Message-ID: <201211150639.qAF6d1AH043293@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@219792?ac=10 Change 219792 by brooks@brooks_zenith on 2012/11/15 06:38:08 Rather than reading in the png file only to stuff it in a buffer, just mmap it in the CHERI case. Affected files ... .. //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/pngbox.c#6 edit Differences ... ==== //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/pngbox.c#6 (text+ko) ==== @@ -225,7 +225,7 @@ static struct chericap c1, c2; static struct iboxstate* -cheri_png_read_start(const char *pngbuffer, size_t pnglen, +cheri_png_read_start(char *pngbuffer, size_t pnglen, uint32_t width, uint32_t height, int slide, enum sbtype sb) { struct sandbox *sandbox; @@ -273,6 +273,7 @@ is->passes_remaining = 0; return (is); error: + munmap(pngbuffer, pnglen); if (is != NULL) { free(__DEVOLATILE(void *, is->buffer)); free(is); @@ -289,7 +290,6 @@ png_read_start(int pfd, uint32_t maxw, uint32_t maxh, int slide, enum sbtype sb) { size_t pnglen; - ssize_t rlen; uint32_t header[9], width, height; struct stat statbuf; char *cheader = (char *)header; @@ -332,24 +332,12 @@ close(pfd); return (NULL); } - /* XXX bogus limit */ - if (statbuf.st_size > 1024 * 1024) { - close(pfd); - return (NULL); - } - if ((pngbuffer = malloc(statbuf.st_size)) == NULL) { + pnglen = statbuf.st_size; + if ((pngbuffer = mmap(NULL, pnglen, PROT_READ, + 0, pfd, 0)) == NULL) { close(pfd); return (NULL); } - pnglen = 0; - while (pnglen < (size_t) statbuf.st_size) { - if ((rlen = read(pfd, pngbuffer + pnglen, - statbuf.st_size - pnglen)) == -1) { - close(pfd); - return (NULL); - } - pnglen += rlen; - } close(pfd); return cheri_png_read_start(pngbuffer, pnglen, width, height, slide, sb);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211150639.qAF6d1AH043293>