diff --git a/lib/webfuse/impl/operation/read.c b/lib/webfuse/impl/operation/read.c index c4c3669..3721f1b 100644 --- a/lib/webfuse/impl/operation/read.c +++ b/lib/webfuse/impl/operation/read.c @@ -10,7 +10,8 @@ #include "webfuse/impl/util/base64.h" #include "webfuse/impl/util/json_util.h" -#define WF_MAX_READ_LENGTH 4096 +// do not read chunks larger than 1 MByte +#define WF_MAX_READ_LENGTH (1024 * 1024) char * wf_impl_fill_buffer( char const * data, @@ -114,12 +115,16 @@ void wf_impl_operation_read( struct wf_impl_operation_context * user_data = fuse_req_userdata(request); struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); - if (NULL != rpc) + if ((NULL != rpc) && (size <= WF_MAX_READ_LENGTH)) { - int const length = (size <= WF_MAX_READ_LENGTH) ? (int) size : WF_MAX_READ_LENGTH; + int const length = (int) size; int handle = (file_info->fh & INT_MAX); wf_impl_jsonrpc_proxy_invoke(rpc, &wf_impl_operation_read_finished, request, "read", "siiii", user_data->name, (int) inode, handle, (int) offset, length); } + else if (size > WF_MAX_READ_LENGTH) + { + fuse_reply_err(request, ENOMEM); + } else { fuse_reply_err(request, ENOENT); diff --git a/test/webfuse/operation/test_read.cc b/test/webfuse/operation/test_read.cc index 8ed3101..c719c62 100644 --- a/test/webfuse/operation/test_read.cc +++ b/test/webfuse/operation/test_read.cc @@ -39,7 +39,7 @@ TEST(wf_impl_operation_read, invoke_proxy) TEST(wf_impl_operation_read, invoke_proxy_limit_size) { MockJsonRpcProxy proxy; - EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1); + EXPECT_CALL(proxy, wf_impl_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(0); MockOperationContext context; EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) @@ -49,6 +49,7 @@ TEST(wf_impl_operation_read, invoke_proxy_limit_size) op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + EXPECT_CALL(fuse, fuse_reply_err(_,_)).Times(1); fuse_req_t request = nullptr; fuse_ino_t inode = 1; diff --git a/test/webfuse/test_server.cc b/test/webfuse/test_server.cc index 85aba28..78b86c3 100644 --- a/test/webfuse/test_server.cc +++ b/test/webfuse/test_server.cc @@ -382,11 +382,11 @@ TEST(server, read_large_file) MockInvokationHander handler; EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber()); EXPECT_CALL(handler, Invoke(StrEq("lookup"), Lookup(1, "a.file"))).Times(1) - .WillOnce(Return("{\"inode\": 2, \"mode\": 420, \"type\": \"file\", \"size\": 1024000}")); + .WillOnce(Return("{\"inode\": 2, \"mode\": 420, \"type\": \"file\", \"size\": 102400}")); EXPECT_CALL(handler, Invoke(StrEq("getattr"), GetAttr(1))).Times(AnyNumber()) .WillRepeatedly(Return("{\"mode\": 420, \"type\": \"dir\"}")); EXPECT_CALL(handler, Invoke(StrEq("getattr"), GetAttr(2))).Times(AnyNumber()) - .WillRepeatedly(Return("{\"mode\": 420, \"type\": \"file\", \"size\": 1024000}")); + .WillRepeatedly(Return("{\"mode\": 420, \"type\": \"file\", \"size\": 102400}")); EXPECT_CALL(handler, Invoke(StrEq("open"), Open(2))).Times(1) .WillOnce(Return("{\"handle\": 42}")); EXPECT_CALL(handler, Invoke(StrEq("read"), _)).Times(AnyNumber()) @@ -394,7 +394,7 @@ TEST(server, read_large_file) int offset = json_integer_value(json_array_get(params, 3)); int length = json_integer_value(json_array_get(params, 4)); - int remaining = (offset < 1024000) ? 1024000 - offset : 0; + int remaining = (offset < 102400) ? 102400 - offset : 0; int count = (length < remaining) ? length : remaining; std::string data = std::string(count, '*');