couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [1/50] git commit: Fix retrieval of headers larger than 4k
Date Wed, 26 Oct 2011 18:05:32 GMT
Updated Branches:
  refs/heads/1319-large-headers-are-corrupted 22fae5003 -> c923e8757 (forced update)

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.


Branch: refs/heads/1319-large-headers-are-corrupted
Commit: c923e87577f2fbe928c965b758167b865a2b1d3e
Parents: 02e808a
Author: Adam Kocoloski <>
Authored: Wed Oct 26 14:04:54 2011 -0400
Committer: Adam Kocoloski <>
Committed: Wed Oct 26 14:06:56 2011 -0400

 src/couchdb/couch_file.erl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index f1d6cc4..2c2f11a 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -433,7 +433,7 @@ load_header(Fd, Block) ->
         RawBin = <<RestBlock/binary, Missing/binary>>
     <<Md5Sig:16/binary, HeaderBin/binary>> =
-        iolist_to_binary(remove_block_prefixes(1, RawBin)),
+        iolist_to_binary(remove_block_prefixes(5, RawBin)),
     Md5Sig = couch_util:md5(HeaderBin),
     {ok, HeaderBin}.

View raw message