Skip to content

Commit 6c5af6c

Browse files
committed
NaN workaround for gridfile_get_numchunks (mongo_c_driver/src/gridfs.c).
gridfile_get_numchunks returns -2147483648 when chunkSize is 0 (converting NaN to int). Conversion this int to ngx_uint_t produce 2147483648 and next ngx_pcalloc throws out of memory.
1 parent cfdf63a commit 6c5af6c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ngx_http_gridfs_module.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,15 @@ static ngx_int_t ngx_http_gridfs_handler(ngx_http_request_t* request) {
796796
length = gridfile_get_contentlength(&gfile);
797797
chunksize = gridfile_get_chunksize(&gfile);
798798
numchunks = gridfile_get_numchunks(&gfile);
799+
800+
// NaN workaround
801+
if (numchunks > INT_MAX)
802+
{
803+
gridfile_destroy(&gfile);
804+
gridfs_destroy(&gfs);
805+
return NGX_HTTP_NOT_FOUND;
806+
}
807+
799808
contenttype = (char*)gridfile_get_contenttype(&gfile);
800809

801810
md5 = (char*)gridfile_get_md5(&gfile);

0 commit comments

Comments
 (0)