PERFORCE change 219792 for review
Brooks Davis
brooks at FreeBSD.org
Thu Nov 15 06:39:02 UTC 2012
http://p4web.freebsd.org/@@219792?ac=10
Change 219792 by brooks at 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);
More information about the p4-projects
mailing list