[mod_python] Request.sendfile() and symlinks

Jim Gallacher jg.lists at sympatico.ca
Sat Oct 15 09:40:51 EDT 2005

Graham Dumpleton wrote:
> Can't look at it until tomorrow, but check code in src/ requestobject.c 
> of mod_python
> source code. The req_sendfile() may well have a bug in it as does a  
> stat of  the
> file to get the length and when it tells Apache to send the file it  
> passes that length
> to the underlying call as the number of bytes to send. If the stat  call 
> is being
> performed on the symlink as it appears and not what it points at, the  
> wrong length
> would be used. The contents of the actual file will be sent though as  
> the symlink
> will be followed correctly at that point, just not enough is sent.

This would seem to be the case, but I'm not sure it represents a bug in 
mod_python since it calls apr_stat() to get the finfo.

  status=apr_stat(&finfo, fname, APR_READ, self->request_rec->pool);

finfo.size is used if len is not specified as a parameter to req_sendfile().

If this is a bug in apr_stat() then perhaps we could use the python 
equivalent as a workaround.

As a temporary fix Wim could check the file size in his own code and use 
req.sendfile(filename, 0, size)


> Maybe someone else can look at this while I get some sleep. ;-)
> Graham
> On 15/10/2005, at 10:37 PM, Wim Heirman wrote:
>> Hello,
>> When I call req.sendfile(filename) where filename is a symbolic  link, 
>> only part of the file is sent to the client (as many bytes as  there 
>> are characters in the symlink's file reference, so for a  symlink 
>> pointing to '../index.html' I get the first 13 bytes of the  correct 
>> file). Is this normal behaviour?
>> Also, I would like to set the Content-Type correctly, based on the  
>> file I'm sending. Using the standard mimetypes package works fine,  
>> but is it possible to use Apache's mime-typing for this? Since the  
>> code for that is already loaded it should be a bit more efficient.
>> Regards,
>> Wim
>> -- 
>> ir. Wim Heirman,
>> ELIS Department, Ghent University, Belgium
>> Phone: +32-9-264.95.27
>> E-mail: wim.heirman at elis.UGent.be
>> http://www.elis.UGent.be/~wheirman/
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list