diff --git a/rhizome_store.c b/rhizome_store.c index cf180b3b..8874de89 100644 --- a/rhizome_store.c +++ b/rhizome_store.c @@ -1103,7 +1103,7 @@ enum rhizome_payload_status rhizome_open_read(struct rhizome_read *read, const r WHYF_perror("lseek64(%s,0,SEEK_END)", alloca_str_toprint(blob_path)); if (read->length <= (uint64_t)pos){ read->blob_fd = fd; - DEBUGF(rhizome_store, "Opened stored file %s as fd %d, len %"PRIu64, blob_path, read->blob_fd, read->length); + DEBUGF(rhizome_store, "Opened stored file %s as fd %d, len %"PRIu64" (%"PRIu64")", blob_path, read->blob_fd, read->length, pos); return RHIZOME_PAYLOAD_STATUS_STORED; } DEBUGF(rhizome_store, "Ignoring file? %s fd %d, len %"PRIu64", seek %zd", blob_path, fd, read->length, pos); @@ -1135,8 +1135,11 @@ static ssize_t rhizome_read_retry(sqlite_retry_state *retry, struct rhizome_read { IN(); if (read_state->blob_fd != -1) { + assert(read_state->offset <= read_state->length); if (lseek64(read_state->blob_fd, (off64_t) read_state->offset, SEEK_SET) == -1) RETURN(WHYF_perror("lseek64(%d,%"PRIu64",SEEK_SET)", read_state->blob_fd, read_state->offset)); + if (bufsz + read_state->offset > read_state->length) + bufsz = read_state->length - read_state->offset; if (bufsz == 0) RETURN(0); ssize_t rd = read(read_state->blob_fd, buffer, bufsz); diff --git a/tests/rhizomeops b/tests/rhizomeops index 21a1559f..7256042b 100755 --- a/tests/rhizomeops +++ b/tests/rhizomeops @@ -1084,6 +1084,7 @@ test_JournalAppendNoHash() { tfw_cat --stdout --stderr assert_stdout_add_file file1 extract_stdout_manifestid BID + extract_stdout_filehash HASH assert [ $(ls "$SERVALINSTANCE_PATH/hash" | wc -l) -eq 1 ] executeOk_servald rhizome journal append $SIDA $BID file2 tfw_cat --stdout --stderr @@ -1092,6 +1093,9 @@ test_JournalAppendNoHash() { executeOk_servald rhizome extract file $BID filex tfw_cat --stdout --stderr assert diff file filex + executeOk_servald rhizome export file $HASH file1x + tfw_cat --stdout --stderr + assert diff file1 file1x } doc_JournalAppendSharedPayload="Journal append produces a shared payload"