diff options
author | Robert Newson <rnewson@apache.org> | 2018-10-15 19:11:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-15 19:11:10 +0100 |
commit | 638554bc5ce82ef8cd516382a6437cf2ca50d682 (patch) | |
tree | 3c121290cd45661cd9c05e0df82cc20dfef5d045 | |
parent | adebd386ee55f65c1b58b3fab232dda9f351c739 (diff) | |
parent | 1b28c58654c049977ce08e1a87ea854f5e5fdd55 (diff) | |
download | couchdb-638554bc5ce82ef8cd516382a6437cf2ca50d682.tar.gz |
Merge pull request #1654 from apache/fix_exceed_limit
Test correct condition for exceed_limit error
-rw-r--r-- | src/couch/src/couch_file.erl | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl index 0c6070dad..d6e4066db 100644 --- a/src/couch/src/couch_file.erl +++ b/src/couch/src/couch_file.erl @@ -614,18 +614,18 @@ read_raw_iolist_int(Fd, {Pos, _Size}, Len) -> % 0110 UPGRADE CODE read_raw_iolist_int(#file{fd = Fd, pread_limit = Limit} = F, Pos, Len) -> BlockOffset = Pos rem ?SIZE_BLOCK, TotalBytes = calculate_total_read_len(BlockOffset, Len), - case Pos + TotalBytes of - Size when Size > F#file.eof -> - couch_stats:increment_counter([pread, exceed_eof]), - {_Fd, Filepath} = get(couch_file_fd), - throw({read_beyond_eof, Filepath}); - Size when Size > Limit -> - couch_stats:increment_counter([pread, exceed_limit]), - {_Fd, Filepath} = get(couch_file_fd), - throw({exceed_pread_limit, Filepath, Limit}); - Size -> - {ok, <<RawBin:TotalBytes/binary>>} = file:pread(Fd, Pos, TotalBytes), - {remove_block_prefixes(BlockOffset, RawBin), Size} + if + (Pos + TotalBytes) > F#file.eof -> + couch_stats:increment_counter([pread, exceed_eof]), + {_Fd, Filepath} = get(couch_file_fd), + throw({read_beyond_eof, Filepath}); + TotalBytes > Limit -> + couch_stats:increment_counter([pread, exceed_limit]), + {_Fd, Filepath} = get(couch_file_fd), + throw({exceed_pread_limit, Filepath, Limit}); + true -> + {ok, <<RawBin:TotalBytes/binary>>} = file:pread(Fd, Pos, TotalBytes), + {remove_block_prefixes(BlockOffset, RawBin), Pos + TotalBytes} end. -spec extract_md5(iolist()) -> {binary(), iolist()}. |