Index: R/digest.R =================================================================== --- R/digest.R (revision 45) +++ R/digest.R (working copy) @@ -54,6 +54,9 @@ if (!isTRUE(!file.info(object)$isdir)) { stop("The specified pathname is not a file: ", object) } + if (file.access(object, 4)) { + stop("The specified file is not readable: ", object) + } } ## if skip is auto (or any other text for that matter), we just turn it ## into 0 because auto should have been converted into a number earlier @@ -68,6 +71,3 @@ PACKAGE="digest") return(val) } - - - Index: tests/digestTest.R =================================================================== --- tests/digestTest.R (revision 45) +++ tests/digestTest.R (working copy) @@ -105,3 +105,10 @@ h1 = as.character(md5sum(fname)) h2 = digest(fname, algo="md5", file=TRUE) stopifnot( identical(h1,h2) ) + +# Make sure we don't core dump with unreadable files. +fname <- tempfile() +cat("Hello World, you won't have access to read me", file=fname) +on.exit(unlink(fname)) +Sys.chmod(fname, mode="0000") +try(digest(fname, file=TRUE)) Index: DESCRIPTION =================================================================== --- DESCRIPTION (revision 45) +++ DESCRIPTION (working copy) @@ -1,5 +1,5 @@ Package: digest -Version: 0.5.1 +Version: 0.5.2 Date: $Date$ Author: Dirk Eddelbuettel with contributions by Antoine Lucas, Jarek Tuszynski, Henrik Bengtsson, Simon Urbanek, Index: src/digest.c =================================================================== --- src/digest.c (revision 45) +++ src/digest.c (working copy) @@ -135,7 +135,7 @@ unsigned char md5sum[16]; if (!(fp = fopen(txt,"rb"))) { - error(strcat("Cannot open input file: ", txt)); + error("Cannot open input file: %s", txt); return(NULL); } if (skip > 0) fseek(fp, skip, SEEK_SET); @@ -167,7 +167,7 @@ unsigned char sha1sum[20]; if (!(fp = fopen(txt,"rb"))) { - error(strcat("Cannot open input file: ", txt)); + error("Cannot open input file: %s", txt); return(NULL); } if (skip > 0) fseek(fp, skip, SEEK_SET); @@ -196,7 +196,7 @@ unsigned long val; if (!(fp = fopen(txt,"rb"))) { - error(strcat("Cannot open input file: ", txt)); + error("Cannot open input file: %s", txt); return(NULL); } if (skip > 0) fseek(fp, skip, SEEK_SET); @@ -224,7 +224,7 @@ unsigned char sha256sum[32]; if (!(fp = fopen(txt,"rb"))) { - error(strcat("Cannot open input file: ", txt)); + error("Cannot open input file: %s", txt); return(NULL); } if (skip > 0) fseek(fp, skip, SEEK_SET);