]> git.kaiwu.me - nginx.git/commitdiff
Merge of r4896: event pipe: fixed handling of buf_to_file data.
authorMaxim Dounin <mdounin@mdounin.ru>
Tue, 13 Nov 2012 11:24:14 +0000 (11:24 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Tue, 13 Nov 2012 11:24:14 +0000 (11:24 +0000)
Input filter might free a buffer if there is no data in it, and in case
of first buffer (used for cache header and request header, aka p->buf_to_file)
this resulted in cache corruption.  Buffer memory was reused to read upstream
response before headers were written to disk.

Fix is to avoid moving pointers in ngx_event_pipe_add_free_buf() to a buffer
start if we were asked to free a buffer used by p->buf_to_file.

This fixes occasional cache file corruption, usually resulted
in "cache file ... has md5 collision" alerts.

Reported by Anatoli Marinov.

src/event/ngx_event_pipe.c
src/http/ngx_http_upstream.c

index c2c79837fcfb428048973b93987b78c3e5d0ef6f..476d56e30e3881e278c53ada3147adcba4e22b4f 100644 (file)
@@ -946,8 +946,15 @@ ngx_event_pipe_add_free_buf(ngx_event_pipe_t *p, ngx_buf_t *b)
         return NGX_ERROR;
     }
 
-    b->pos = b->start;
-    b->last = b->start;
+    if (p->buf_to_file && b->start == p->buf_to_file->start) {
+        b->pos = p->buf_to_file->last;
+        b->last = p->buf_to_file->last;
+
+    } else {
+        b->pos = b->start;
+        b->last = b->start;
+    }
+
     b->shadow = NULL;
 
     cl->buf = b;
index 6c34f39d64fbac74b354d79fad3c5d9622d71cad..75ef64e5560007192bb3edf925a7744cda718af8 100644 (file)
@@ -2287,6 +2287,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
             return;
         }
 
+        p->buf_to_file->start = u->buffer.start;
         p->buf_to_file->pos = u->buffer.start;
         p->buf_to_file->last = u->buffer.pos;
         p->buf_to_file->temporary = 1;