Skip to content
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

fix: use Long_val for sendfile() parameters to fix file copying in docker #10333

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 10333.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- fix overflow in sendfile stubs (copy of large files could fail or end with
truncated files) (#10333, @tonyfettes)
6 changes: 3 additions & 3 deletions otherlibs/stdune/src/copyfile_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ CAMLprim value stdune_copyfile(value v_from, value v_to) {
caml_failwith("copyfile: only on macos");
}

static int dune_sendfile(int in, int out, int length) {
int ret;
static int dune_sendfile(int in, int out, size_t length) {
ssize_t ret;
while (length > 0) {
ret = sendfile(out, in, NULL, length);
if (ret < 0) {
Expand All @@ -90,7 +90,7 @@ CAMLprim value stdune_sendfile(value v_in, value v_out, value v_size) {
caml_release_runtime_system();
/* TODO Use copy_file_range once we have a good mechanism to test for its
* existence */
int ret = dune_sendfile(FD_val(v_in), FD_val(v_out), Int_val(v_size));
int ret = dune_sendfile(FD_val(v_in), FD_val(v_out), Long_val(v_size));
emillon marked this conversation as resolved.
Show resolved Hide resolved
caml_acquire_runtime_system();
if (ret < 0) {
uerror("sendfile", Nothing);
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/sendfile-large-file.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ We create a large file and check that it is copied completely.
4294967299

$ dune_cmd stat size _build/default/file.dat
3
4294967299

(3 indicates that the file size is taken modulo 2**32)
Loading