You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Remy Tensen <RT...@TriLogic.nl> on 1999/02/02 01:09:49 UTC

mod_cgi/3811: Content_Length doesn't match the length of the content received.

>Number:         3811
>Category:       mod_cgi
>Synopsis:       Content_Length doesn't match the length of the content received.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Class:          support
>Submitter-Id:   apache
>Arrival-Date:   Mon Feb  1 16:10:01 PST 1999
>Last-Modified:
>Originator:     RTensen@TriLogic.nl
>Organization:
apache
>Release:        1.3.4
>Environment:
Windows NT 4.0 SP 3, I am using the precompiled binary and 
for CGI programming MSVC.
>Description:
When using multipart mime to send a file to a CGI program 
written in C, the fread function reads less bytes than the 
CONTENT_LENGTH variable indicates.
>How-To-Repeat:

>Fix:
The difference in size is caused by the default mode of stdin.
The stdin handle defaults to text mode and when in text mode 
every CR LF pair is replaced by a single LF. The fread function
does not return the bytes read but the bytes written into the 
specified buffer and this is one less for every CR LF pair, 
since mime requires CR LF pairs their occurrence is quite 
common. 
Fixing the problem was easy just set the stdin port to
binary mode. 
To do this I used the following code:

setmode( fileno( stdin ), O_BINARY );

I hope this report saves some people a couple of hours (it
would have saved me some time).
>Audit-Trail:
>Unformatted:
[In order for any reply to be added to the PR database, ]
[you need to include <ap...@Apache.Org> in the Cc line ]
[and leave the subject line UNCHANGED.  This is not done]
[automatically because of the potential for mail loops. ]
[If you do not include this Cc, your reply may be ig-   ]
[nored unless you are responding to an explicit request ]
[from a developer.                                      ]
[Reply only with text; DO NOT SEND ATTACHMENTS!         ]