Opened 10 years ago

Closed 8 years ago

#504 closed defect (fixed)

the resourcenot release in time when file be truncated

Reported by: Dane Zhang Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.5.x
Keywords: sendfile, file be truncated Cc:
uname -a: Linux YFXINX81-32-DX-APP.opi.com. 2.6.39-900.109.1.reiserfs.el5uek #1 SMP Fri Jun 28 20:11:06 CST 2013 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.5.7
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
configure arguments: --prefix=/diska/sys_dev/ng_patch/

Description

1,a client request a file;
2,nginx response the request use sendfile,;
3,the file be truncated (rsync etc)
4,nginx have not detect this condition in time;
5,nginx release the resource (local fd and socket) after time out;

patch:
--- ngx_linux_sendfile_chain.c 2014-02-14 11:18:43.772856547 +0800
+++ ngx_linux_sendfile_chain.c 2014-02-14 14:28:55.644845942 +0800
@@ -286,6 +286,22 @@

sent = rc > 0 ? rc : 0;


+ if (rc == 0)
+ {
+ ngx_file_info_t new_info;
+ if (ngx_file_info(file->file->name.data, &new_info) == 0)
+ {
+ if (new_info.st_size < file->file_last)
+ {
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0,
+ "sendfile error: %d, %s, %O < %O",
+ rc, file->file->name.data, new_info.st_size, file->file_last);
+ wev->error = 1;
+ return NGX_CHAIN_ERROR;
+ }
+ }
+ }
+

Change History (2)

comment:1 by Leslie Zhai, 10 years ago

because the FILE has been CHANGED, if the total size (in bytes) new_info.st_size is smaller than file_last (defined in struct ngx_buf_s), perhaps the file_pos was also changed!

comment:2 by Maxim Dounin, 8 years ago

Resolution: fixed
Status: newclosed

Truncation detection for sendfile() on Linux and Solaris was added in nginx 1.9.13, see 4df3d9fcdee8 and 646985c55393. File truncation is properly detected now on these platforms as well and results in "sendfile() reported that ... was truncated at ..." alerts, much like on FreeBSD and OS X.

Note: See TracTickets for help on using tickets.