Bug 1905454 - Make sure the consumed data is erased, r=necko-reviewers,valentin

No matter what the consumedCount is, the previous code always erases 1 byte of data, which is not correct. We should ensure that the amount of data removed matches the consumedCount.

Differential Revision: https://phabricator.services.mozilla.com/D218551
This commit is contained in:
Kershaw Chang 2024-08-06 07:24:27 +00:00
parent 5f37c4fa62
commit 3f851f4ddf
2 changed files with 9 additions and 1 deletions

View File

@ -157,7 +157,8 @@ nsresult nsIncrementalStreamLoader::WriteSegmentFun(
// Adopting elems back (at least its portion).
self->mData.replaceRawBuffer(elems, length);
if (consumedCount > 0) {
self->mData.erase(self->mData.begin() + consumedCount);
self->mData.erase(self->mData.begin(),
self->mData.begin() + consumedCount);
}
}
}

View File

@ -47,6 +47,13 @@ var tests = [
consume: [0],
dataChunks: ["E", "E"],
},
{
data: "123456789",
chunks: [2, 3, 4],
status: Cr.NS_OK,
consume: [1, 2, 6],
dataChunks: ["12", "2345", "456789", ""],
},
];
/**