You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@httpd.apache.org by bu...@apache.org on 2013/05/14 07:57:51 UTC

[Bug 54962] New: Apache will set incorrect Content-Length header and may serve partial files

https://issues.apache.org/bugzilla/show_bug.cgi?id=54962

            Bug ID: 54962
           Summary: Apache will set incorrect Content-Length header and
                    may serve partial files
           Product: Apache httpd-2
           Version: 2.5-HEAD
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Core
          Assignee: bugs@httpd.apache.org
          Reporter: Richard_Fliam@cable.comcast.com
    Classification: Unclassified

We have several files which are moved (renamed) on top of frequently (about
every 2 seconds). 

A rename or move operation is atomic in the kernel, and thus should not cause
issues. However, due to the nature of the way Apache serves these files it will
periodically serve an incorrect Content-Length header and a truncated file or
not enough bits.

Steps to Reproduce:
Take a file, perhaps randomly generated.
Move (mv, or c rename()) a new one of differing size onto it with a relatively
high frequency.

Cause:
Apache "stats" a file on receiving a request. It than opens a file descriptor
for that file on line 4314 of core.c, and sets the content length header using
`ap_set_content_length(r, r->finfo.size)` on 4328. This is the core of the
problem, r->finfo.size is from a `stat()` that may not be the same inode.

The better (correct?) behavior is to use `fstat()` on the open file descriptor
to set the Content-Length header as well as send size for sendfile etc. As file
descriptors refer to an inode in most operating systems this prevents the
underlying race on files which are being (atomically) updated.

To be clear this is not the same as having issues reading from a file that is
being modified, the file is updated atomically and many other application (such
as Python) handle this correctly.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org