Skip to content

Commit

Permalink
Re-implements how a local file is read. The previous code was filling
Browse files Browse the repository at this point in the history
the buffer, independently of its size. That caused the buffer to grow
unexpectedly under some unusual circumstances (A gzip encoder with no
compression, for instance).

git-svn-id: svn://cherokee-project.com/cherokee/trunk@6546 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Apr 21, 2011
1 parent 607dabe commit e33b1b3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
3 changes: 3 additions & 0 deletions cherokee/connection.c
Expand Up @@ -1419,6 +1419,9 @@ cherokee_connection_step (cherokee_connection_t *conn)
*/
cherokee_buffer_swap_buffers (&conn->buffer, &conn->encoder_buffer);
cherokee_buffer_clean (&conn->encoder_buffer);

TRACE (ENTRIES",encoder", "Sizes: Conn %d bytes, Enc %d bytes\n",
conn->buffer.size, conn->encoder_buffer.size);
}

/* Chunked encoding header
Expand Down
14 changes: 1 addition & 13 deletions cherokee/handler_file.c
Expand Up @@ -850,19 +850,7 @@ cherokee_handler_file_step (cherokee_handler_file_t *fhdl, cherokee_buffer_t *bu
#endif
/* Check the amount to read
*/
size = buffer->size - 1;

if (conn->encoder != NULL) {
size -= 96; /* Room for the header */
}

if (size > (conn->range_end - fhdl->offset + 1)) {
size = conn->range_end - fhdl->offset + 1;
} else {
/* Align read size on a 4 byte limit
*/
size &= ~3;
}
size = MIN (DEFAULT_READ_SIZE, (conn->range_end - fhdl->offset + 1));

/* Check overflow */
if (unlikely (size > buffer->size)) {
Expand Down
4 changes: 2 additions & 2 deletions cherokee/macros.h
Expand Up @@ -86,8 +86,8 @@
# define no_return
#endif

#define DEFAULT_RECV_SIZE 2048
#define DEFAULT_READ_SIZE 8192
#define DEFAULT_RECV_SIZE ( 2 * 1024)
#define DEFAULT_READ_SIZE (16 * 1024)
#define MAX_HEADER_LEN 8192
#define MAX_HEADER_CRLF 8
#define MAX_KEEPALIVE 500
Expand Down

0 comments on commit e33b1b3

Please sign in to comment.