Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Failure of [file type] on large files

Closed / Fixed458576ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2001-09-05 00:06:37
On x86 linux the "file type" command fails with an
error on files that are more than 2G in length. 
Clearly, what is happening is that a common subroutine
is being called to stat the file and the 2G file length
overflows a tcl integer.

However, the length isn't needed at all for "file type"
to return the correct result.  There are probably a
similar problems with other variants of the file
command.

     Andy
dkf Ticket [458576ffff]: 3 changes [History diff]2001-09-05 16:10:39
vincentdarleyplain2001-09-05 21:06:14
Logged In: YES 
user_id=32170

Unfortunately, the 'clearly what is happening' above boils 
down to:

Tcl calls 'Tcl_FSLstat' which calls 'TclpObjLstat' which 
calls 'lstat' which returns an error code.  Tcl receives 
the error code and passes the error on.

The only options available seem to be:

(i) replace 'lstat' with a 64-bit aware version (with the 
numerous knock-on effects that may have).
(ii) if 'lstat' returns a particular POSIX error code which 
can be interpreted to mean 'this file is too big', perhaps 
we can take more subtle remedial action.

I suggest the reporter of this bug try to work out what is 
going on and which of (i), (ii) might solve the problem.

cheers,   Vince.
dkfplain2001-09-05 21:43:36
Logged In: YES 
user_id=79902

'man lstat' says EOVERFLOW on Solaris, and recommends
lstat64(..., struct stat64 *...) as a transitional
interface.  Whatever *that* means...

The difference between 'struct stat' and 'struct stat64' is
in the typing of selected fields (st_ino, st_size, and
st_blocks) whose names gain a '64' immediately preceding the
'_t' (and which are presumably now 64-bit entities.)
vincentdarleyplain2001-09-05 22:07:11
Logged In: YES 
user_id=32170

I guess this means someone could cobble together option 
(ii) below by checking for an EOVERFLOW return code and 
doing appropriate stuff.  Not sure if it's worth doing 
really, though (the problem is that we don't know what the 
caller of lstat is after --- do they just want the 'type' 
or are they actually after the size?).  Might be best for 
someone who uses these things to add proper large file 
support to Tcl.  It would be nice if this could get into 
Tcl 8.4.
andyvplain2001-09-05 23:30:56
Logged In: YES 
user_id=29655

I've already worked around my immediate problem.  I needed
to know if the file was a directory or not, and 'file
isdirectory' works fine on large files.

I did download and compile 8.4-alpha with --enable-64bits
and as far as I can tell, it didn't use lstat64(). 
Replacing lstat() with lstat64() doesn't necessarily have to
involve all the pain of replacing tcl integers with 64-bit
integers; In the case of 'file type', the length is never
needed.

Perhaps a flag could be added to TclpObjLstat indicating
whether the length was needed or not.  If the length is
needed and was greater than 2^31, then an error could be
raised.
vincentdarleyplain2001-09-07 00:44:25
Logged In: YES 
user_id=32170

I'm afraid '--enable-64bits' is badly named and nothing to 
do with this.

Adding a flag to every use of lstat for one particular 
purpose seems like a mess (how many other 'one particular 
purposes' can we think of).  Another option might be for 
this code in tclCmdAH.c:

case FILE_TYPE: {
    struct stat buf;

    if (objc != 3) {
    goto only3Args;
    }
    if (GetStatBuf(interp, objv[2], Tcl_FSLstat, 
&buf) != TCL_OK) {
return TCL_ERROR;
    }
    Tcl_SetStringObj(Tcl_GetObjResult(interp), 
    GetTypeFromMode((unsigned short) 
buf.st_mode), -1);
    return TCL_OK;
}

to check if 'Tcl_GetErrno()' is EOVERFLOW and if so not to 
return TCL_ERROR, but rather to go ahead and use the 
information it needs anyway.  This assumes that 
when 'lstat' fails with EOVERFLOW it still fills in the 
entries it can in the stat buffer.   Feel free to test this 
out and contribute a patch.
nobodyplain2001-09-11 02:22:36
Logged In: NO 

The main problem is that there are actually quite a few places that (l)stat files, and if you change the 
interface in one place to take account of the possibility of large files, then you have to change it throughout. 
Which is a lot of work. Furthermore, I do not know if there is any cross-platform agreement on what the 
interface for dealing with large files should be, and the documentation on Solaris does not make me inclined 
to believe that what is there is necessarily common throughout. If, as I suspect, large file support uses a 
different API on each platform (urk!) then we will need to develop a suitable set of macros to detect this in 
tcl.m4, and even in the case where this is not, we still have the problem of how to represent numbers larger 
than 2G (as would be returned from [file size] applied to a large file) in Tcl where we do not currently 
support numbers larger than that if the size of long is only 32 bits. Which means that we need to do a 
*major* rearchitecturing of the whole Tcl core to support this. :^(

I suppose the bullet must be bitten some time, but it is going to be much work...
dkfplain2001-09-13 22:14:39
Logged In: YES 
user_id=79902

See also #219197, and I think that you can't assume anything
about the contents of the stat buffer after a failed stat().
andyvplain2001-09-13 23:29:27
Logged In: YES 
user_id=29655

I thought I would have some time to give a better look at
this, but I don't think I will.

In my view, the tcl developers need to make tcl aware of
more than 32 bits.
dkfplain2001-09-14 16:05:32
Logged In: YES 
user_id=79902

We're aware of the need to support more than 32-bit numbers
on systems where sizeof(long) is 4 (some architectures
support large files and numbers already due to increased
word size) but until we do our support for large files is
going to be patchy.  The first thing we need is to get
configure to work out what the type of 64-bit numbers is so
we can support them in Tcl_Objs (which are already large
enough so there'll be no incompatability there.)  Only once
that's addressed will we be able to sort out everything
else.  :^(
dkfplain2001-10-09 16:40:24
Logged In: YES 
user_id=79902

See dkf-64bit-support-branch
vincentdarleyplain2002-01-31 00:38:26
Logged In: YES 
user_id=32170

Isn't the '64bit' support branch pretty much complete and 
passes all tests?  In that case shouldn't someone on the 
TCT schedule a vote for the relevant TIP so we can get this 
bug fixed?
dkfplain2002-01-31 17:11:47
Logged In: YES 
user_id=79902

I'll try to get to that when I have time, but I'm currently
up to my eyeballs in other work which has a tight schedule
with no opportunity to slip it either (I'm rewriting slides,
notes and exercises for a lecture on concurrency given later
this month by my boss, in case you're interested.)  Maybe at
the weekend I'll be able to double-check that all the things
I want to do are in the TIP and then do a CFV, but no
guarantees there...
dkf Closed ticket [458576ffff]. [History diff]2002-02-16 04:15:20
Log in (anonymous is fine) to add a comment.