Skip to content

Commit 867f979

Browse files
committed
BugFix in ByteBuffer and StripedBlockUtil
Signed-off-by: M1eyu2018 <857037797@qq.com>
1 parent 181d5d0 commit 867f979

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/client/ByteBuffer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ class ByteBuffer {
6161

6262
// Write Methods
6363
ByteBuffer & put(const ByteBuffer * bb) {
64-
for (uint32_t i = 0; i < bb->limit(); i++)
64+
int n = bb->remaining();
65+
if (n > remaining()) {
66+
throw std::runtime_error("buffer over flow");
67+
}
68+
for (uint32_t i = bb->position(); i < bb->limit(); i++)
6569
append<int8_t>(bb->get(i));
6670

6771
return *this;

src/client/StripedBlockUtil.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ void StripedBlockUtil::divideOneStripe(shared_ptr<ECPolicy> ecPolicy,
8787

8888
// Step 4: calculate each chunk's position in destination buffer. Since the
8989
// whole read range is within a single stripe, the logic is simpler here.
90-
int bufOffset =
91-
static_cast<int>(rangeStartInBlockGroup % (static_cast<int>(cellSize * dataBlkNum)));
90+
int done = 0;
9291
for (int i = 0; i < static_cast<int>(cells.size()); i++) {
9392
StripingCell & cell = cells[i];
9493
long cellStart = cell.idxInInternalBlk * cellSize + cell.offset;
@@ -106,11 +105,11 @@ void StripedBlockUtil::divideOneStripe(shared_ptr<ECPolicy> ecPolicy,
106105
chunk = shared_ptr<StripingChunk>(new StripingChunk());
107106
s->chunks[cell.idxInStripe] = chunk;
108107
}
109-
int pos = static_cast<int>(bufOffset + overlapStart - cellStart);
108+
int pos = static_cast<int>(done + overlapStart - cellStart);
110109
chunk->getChunkBuffer()->addSlice(buf, pos, overLapLen);
111110
}
112111
}
113-
bufOffset += cell.size;
112+
done += cell.size;
114113
}
115114

116115
// Step 5: prepare ALLZERO blocks

0 commit comments

Comments
 (0)