New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-T /dev/stdin
/-T /dev/fd/$n
may upload with an incorrect content length on BSDs
#12177
Labels
Comments
emanuele6
added a commit
to emanuele6/curl
that referenced
this issue
Oct 21, 2023
curl will now also compute the content-length of the transfer if stdin is the file to upload and stdin is a regular file, using its file size. Since, while being a regular file, stdin could not have its offset at the start of the file, curl will now also get the current offset into the upload file's file descriptor and use (filesize - offset) as content-length for transfer instead of just using the full filesize. This also fixes a bug on BSDs where open("/dev/fd/N") behaves like dup(N), so, if N is a file descriptor to a regular file, the file offset of the file descriptor returned by open() may not have been at the start of the file despite curl's previous assumption. Since I don't know anything about VMS systems, I left the behaviour for VMS unchanged; on VMS, curl will still perform a chunked transfer if the upload file is stdin. Fixes curl#12171 Fixes curl#12177
emanuele6
added a commit
to emanuele6/curl
that referenced
this issue
Oct 21, 2023
curl will now also compute the content-length of the transfer if stdin is the file to upload and stdin is a regular file, using its file size. Since, while being a regular file, stdin could not have its offset at the start of the file, curl will now also get the current offset into the upload file's file descriptor and use (filesize - offset) as content-length for transfer instead of just using the full filesize. This also fixes a bug on BSDs where open("/dev/fd/N") behaves like dup(N), so, if N is a file descriptor to a regular file, the file offset of the file descriptor returned by open() may not have been at the start of the file despite curl's previous assumption. Since I don't know anything about VMS systems, I left the behaviour for VMS unchanged; on VMS, curl will still perform a chunked transfer if the upload file is stdin. Fixes curl#12171 Fixes curl#12177
emanuele6
added a commit
to emanuele6/curl
that referenced
this issue
Oct 24, 2023
curl will now also compute the content-length of the transfer if stdin is the file to upload and stdin is a regular file, using its file size. Since, while being a regular file, stdin could not have its offset at the start of the file, curl will now also get the current offset into the upload file's file descriptor and use (filesize - offset) as content-length for transfer instead of just using the full filesize. This also fixes a bug on BSDs where open("/dev/fd/N") behaves like dup(N), so, if N is a file descriptor to a regular file, the file offset of the file descriptor returned by open() may not have been at the start of the file despite curl's previous assumption. Since I don't know anything about VMS systems, I left the behaviour for VMS unchanged; on VMS, curl will still perform a chunked transfer if the upload file is stdin. I updated tests that were testing chunked transfers for stdin to use <stdin pipe="yes"> since now curl only performs a chunked transfer by default if the upload file (stdin or not) is not a regular file. Fixes curl#12171 Fixes curl#12177
emanuele6
added a commit
to emanuele6/curl
that referenced
this issue
Oct 24, 2023
curl will now also compute the content-length of the transfer if stdin is the file to upload and stdin is a regular file, using its file size. Since, while being a regular file, stdin could not have its offset at the start of the file, curl will now also get the current offset into the upload file's file descriptor and use (filesize - offset) as content-length for transfer instead of just using the full filesize. This also fixes a bug on BSDs where open("/dev/fd/N") behaves like dup(N), so, if N is a file descriptor to a regular file, the file offset of the file descriptor returned by open() may not have been at the start of the file despite curl's previous assumption. Since I don't know anything about VMS systems, I left the behaviour for VMS unchanged; on VMS, curl will still perform a chunked transfer if the upload file is stdin. I updated tests that were testing chunked transfers for stdin to use <stdin pipe="yes"> since now curl only performs a chunked transfer by default if the upload file (stdin or not) is not a regular file. Fixes curl#12171 Fixes curl#12177
emanuele6
added a commit
to emanuele6/curl
that referenced
this issue
Oct 24, 2023
curl will now also compute the content-length of the transfer if stdin is the file to upload and stdin is a regular file, using its file size. Since, while being a regular file, stdin could not have its offset at the start of the file, curl will now also get the current offset into the upload file's file descriptor and use (filesize - offset) as content-length for transfer instead of just using the full filesize. This also fixes a bug on BSDs where open("/dev/fd/N") behaves like dup(N), so, if N is a file descriptor to a regular file, the file offset of the file descriptor returned by open() may not have been at the start of the file despite curl's previous assumption. Since I don't know anything about VMS systems, I left the behaviour for VMS unchanged; on VMS, curl will still perform a chunked transfer if the upload file is stdin. I updated tests that were testing chunked transfers for stdin to use <stdin pipe="yes"> since now curl only performs a chunked transfer by default if the upload file (stdin or not) is not a regular file. Fixes curl#12171 Fixes curl#12177
emanuele6
added a commit
to emanuele6/curl
that referenced
this issue
Oct 24, 2023
curl will now also compute the content-length of the transfer if stdin is the file to upload and stdin is a regular file, using its file size. Since, while being a regular file, stdin could not have its offset at the start of the file, curl will now also get the current offset into the upload file's file descriptor and use (filesize - offset) as content-length for transfer instead of just using the full filesize. This also fixes a bug on BSDs where open("/dev/fd/N") behaves like dup(N), so, if N is a file descriptor to a regular file, the file offset of the file descriptor returned by open() may not have been at the start of the file despite curl's previous assumption. Since I don't know anything about VMS systems, I left the behaviour for VMS unchanged; on VMS, curl will still perform a chunked transfer if the upload file is stdin. I updated tests that were testing chunked transfers for stdin to use <stdin pipe="yes"> since now curl only performs a chunked transfer by default if the upload file (stdin or not) is not a regular file. And I added a new test (258) that verifies that stdin is uploaded with content-length (not transfer-encoding:chunked) if it is a regular file. Fixes curl#12171 Fixes curl#12177
emanuele6
added a commit
to emanuele6/curl
that referenced
this issue
Oct 24, 2023
curl will now also compute the content-length of the transfer if stdin is the file to upload and stdin is a regular file, using its file size. Since, while being a regular file, stdin could not have its offset at the start of the file, curl will now also get the current offset into the upload file's file descriptor and use (filesize - offset) as content-length for transfer instead of just using the full filesize. This also fixes a bug on BSDs where open("/dev/fd/N") behaves like dup(N), so, if N is a file descriptor to a regular file, the file offset of the file descriptor returned by open() may not have been at the start of the file despite curl's previous assumption. Since I don't know anything about VMS systems, I left the behaviour for VMS unchanged; on VMS, curl will still perform a chunked transfer if the upload file is stdin. I updated tests that were testing chunked transfers for stdin to use <stdin pipe="yes"> since now curl only performs a chunked transfer by default if the upload file (stdin or not) is not a regular file. And I added a new test (268) that verifies that stdin is uploaded with content-length (not transfer-encoding:chunked) if it is a regular file. Fixes curl#12171 Fixes curl#12177
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did this
-T path
will statpath
to figure out its size in bytes to use it asContent-Length
if it is a regular file.The problem with that is that, on BSDs and some other UNIXes (not Linux),
open(path)
may not give you a file descriptor with a 0 offset from the start of the file.On BSDs, if the path given to open is to a
/dev/fd/*
file or/dev/stdin
,/dev/stdout
,/dev/stderr
, that will trigger a special behaviour foropen
:open
on BSD, instead of reopening the file related to that file descriptor with different open modes like in Linux, will actually duplicate the file descriptor specified by that path if its open modes are compatible with the ones requested byopen
, and otherwise fail.Since
-T /dev/fd/4
for example, will effectively just be adup(4)
, whencurl
will open the path it thinks is for a regular file (because fd 4 is indeed a file descriptor for a regular file,myfile
), it will not find itself at byte offset 0 into the file, and will send less data thanContent-Length
.I expected the following
I expected:
curl
should checked the current offset into the regular file and use itssize - offset
as content length instead of just using its size.Other possible alternatives:
Those solutions are all fairly easy to implement. I, personally, would prefer either the first or the second approach, I don't really like the idea of
curl
seeking back to 0 after opening.curl/libcurl version
curl 8.2.1 (I am using my https://sdf.org/ shell account to test this)
operating system
The text was updated successfully, but these errors were encountered: