Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: pws-21: minor fixes



"Andrej Borsenkow" wrote:
> One thing, that still bothers me, is mapfile. In case of LFS (64-on-32)
> address space is most probably limited to 32 bits, that means, it is
> impossible to map large file. I do not supose, anybody would do this on
> purpose, but what happens if somebody makes mistake? Currently file size is
> silently passed to mmap ... that truncates it and (in worst case) maps some
> part of file. And even worse, can file be truncated as a result?

The length parameter to mmap() is size_t, which is quite often shorter than
off_t on this sort of system, so certainly it's possible to have problems.
But this must surely be completely generic to just about any program that
has to have a complete file in memory, which presumably includes any simple
text editor --- it's certainly far beyond the scope of a zsh module to
solve.  However, I can add some more dark hints to the already longish
`Limitations' section of the manual.

The truncation problem can only happen when you read and then write the
file (e.g. vared); simply reading the file with $mapfile[..] can't hurt it
since that only uses PROT_READ so has kernel-level protection against
writing.  Any assignment to mapfile[...] is fraught with danger anyway (for
example, it doesn't respect NOCLOBBER, though I could presumably make it);
I would think problems of truncation of 2GB files are the least of anyone's
worries.

--- Doc/Zsh/mod_mapfile.yo.lim	Sat May 22 16:28:41 1999
+++ Doc/Zsh/mod_mapfile.yo	Thu Jun 10 16:08:00 1999
@@ -35,7 +35,9 @@
 gain in efficiency over use of other mechanisms.  Note in particular that
 the whole contents of the file will always reside physically in memory when
 accessed (possibly multiple times, due to standard parameter subsitution
-operations).
+operations).  In particular, this means handling of sufficiently long files
+(greater than the machine's swap space, or than the range of the pointer
+type) will be incorrect.
 
 No errors are printed or flagged for non-existent, unreadable, or
 unwriteable files, as the parameter mechanism is too low in the shell

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



Messages sorted by: Reverse Date, Date, Thread, Author