From a6352493651f6f8e3430269555421b5599a77809 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Wed, 26 Oct 2011 14:04:54 -0400 Subject: Fix retrieval of headers larger than 4k Our headers start with a <<1>> and then four bytes indicating the length of the header and its checksum. When the header is larger than 4090 bytes it will be split across multiple blocks in the file and will need to be reassembled on read. The reassembly consists of stripping out <<0>> from the beginning of each subsequent block in the remove_block_prefixes/2 function. The bug here is that we tell remove_block_prefixes that we're starting 1 byte into the current block instead of 5, so it ends up removing one good byte from the header and injecting one or more random <<0>>s. Headers larger than 4k are very rare and generally require a view group with a huge number of indexes or indexes with fairly large reductions, which explains why this bug has gone undetected until now. Closes COUCHDB-1319. --- apps/couch/src/couch_file.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/couch/src') diff --git a/apps/couch/src/couch_file.erl b/apps/couch/src/couch_file.erl index dfc1f822..1985f5eb 100644 --- a/apps/couch/src/couch_file.erl +++ b/apps/couch/src/couch_file.erl @@ -528,7 +528,7 @@ load_header(Fd, Block) -> RawBin = <> end, <> = - iolist_to_binary(remove_block_prefixes(1, RawBin)), + iolist_to_binary(remove_block_prefixes(5, RawBin)), Md5Sig = couch_util:md5(HeaderBin), {ok, HeaderBin}. -- cgit v1.2.3