Henrik Bengtsson
2007-Mar-31 06:28 UTC
[Rd] Too long pathname in bitmap() crashes R on WinXP
Hi,
using too long pathnames for bitmap() crash R on WinXP. I've verified
that this is the case with R version 2.4.1 Patched (2007-03-25 r40958)
and R version 2.5.0 alpha (2007-03-30 r40957). I cannot reproduce it
on Linux.
REPRODUCIBLE EXAMPLE:
% Rterm --vanilla
# Tell R where Ghostscript is
gsexe <- "C:/gs/gs8.54/bin/gswin32c.exe";
gsexe <- "C:/Program Files/gs/gs8.56/bin/gswin32c.exe";
gsexe <- shortPathName(gsexe);
Sys.putenv("R_GSCMD"=gsexe);
# Total length of pathname (R crashes when it is too long)
n <- 130;
# Output path
path <- tempdir();
# Filename
name <- paste(rep("a", n-5-nchar(path)), collapse="");
filename <- paste(name, "png", sep=".");
# Full pathname
pathname <- file.path(path, filename);
print(pathname);
stopifnot(nchar(pathname) == n);
bitmap(pathname);
plot(1);
dev.off();
R crash with dev.off(), but the PNG file is still created.
# MORE DETAILED EXAMPLE:
n <- 130;
path <- tempdir();
name <- paste(rep("a", n-5-nchar(path)), collapse="");
filename <- paste(name, "png", sep=".");
pathname <- file.path(path, filename);
print(pathname);
# Tell R where Ghostscript is
gsexe <- "C:/gs/gs8.54/bin/gswin32c.exe";
gsexe <- "C:/Program Files/gs/gs8.56/bin/gswin32c.exe";
gsexe <- shortPathName(gsexe);
cmd <- paste(gsexe, " -dNOPAUSE -dBATCH -q -sDEVICE=png256 -r72
-g432x432 -sOutputFile=", pathname, sep="");
print(cmd);
print(nchar(cmd));
tmp <- tempfile();
postscript(file=tmp, width=6, height=6, pointsize=9, paper="special",
horizontal=FALSE, print.it=TRUE, command=cmd);
plot(1);
dev.off();
It seems to have to do with the length of 'cmd' (since the possible
pathname length varies with the length of 'gsexe' used).
Any ideas?
/Henrik
Prof Brian Ripley
2007-Mar-31 07:27 UTC
[Rd] Too long pathname in bitmap() crashes R on WinXP
It is also possible to trigger this on Unix: a buffer in postscript() is PATH_MAX when it should be 2*PATH_MAX + 2. I'll fix this in 2.5.0 alpha (there is also a potential issue inside the Windows' runcmd that needs fixing). On Fri, 30 Mar 2007, Henrik Bengtsson wrote:> Hi, > > using too long pathnames for bitmap() crash R on WinXP. I've verified > that this is the case with R version 2.4.1 Patched (2007-03-25 r40958) > and R version 2.5.0 alpha (2007-03-30 r40957). I cannot reproduce it > on Linux. > > REPRODUCIBLE EXAMPLE: > > % Rterm --vanilla > > # Tell R where Ghostscript is > gsexe <- "C:/gs/gs8.54/bin/gswin32c.exe"; > gsexe <- "C:/Program Files/gs/gs8.56/bin/gswin32c.exe"; > gsexe <- shortPathName(gsexe); > Sys.putenv("R_GSCMD"=gsexe); > > # Total length of pathname (R crashes when it is too long) > n <- 130; > > # Output path > path <- tempdir(); > > # Filename > name <- paste(rep("a", n-5-nchar(path)), collapse=""); > filename <- paste(name, "png", sep="."); > > # Full pathname > pathname <- file.path(path, filename); > print(pathname); > stopifnot(nchar(pathname) == n); > > bitmap(pathname); > plot(1); > dev.off(); > > R crash with dev.off(), but the PNG file is still created. > > > # MORE DETAILED EXAMPLE: > > n <- 130; > path <- tempdir(); > name <- paste(rep("a", n-5-nchar(path)), collapse=""); > filename <- paste(name, "png", sep="."); > pathname <- file.path(path, filename); > print(pathname); > > # Tell R where Ghostscript is > gsexe <- "C:/gs/gs8.54/bin/gswin32c.exe"; > gsexe <- "C:/Program Files/gs/gs8.56/bin/gswin32c.exe"; > gsexe <- shortPathName(gsexe); > > cmd <- paste(gsexe, " -dNOPAUSE -dBATCH -q -sDEVICE=png256 -r72 > -g432x432 -sOutputFile=", pathname, sep=""); > print(cmd); > print(nchar(cmd)); > > tmp <- tempfile(); > postscript(file=tmp, width=6, height=6, pointsize=9, paper="special", > horizontal=FALSE, print.it=TRUE, command=cmd); > plot(1); > dev.off(); > > It seems to have to do with the length of 'cmd' (since the possible > pathname length varies with the length of 'gsexe' used). > > Any ideas? > > /Henrik > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595