Skip to content

Commit

Permalink
Handle cases where ranges to read are completely outside the range of…
Browse files Browse the repository at this point in the history
… channels available in the fseq file
  • Loading branch information
dkulp committed Oct 24, 2019
1 parent ac1419b commit d635549
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/fseq/FSEQFile.cpp
Expand Up @@ -900,7 +900,8 @@ class V2ZSTDCompressionHandler : public V2CompressedHandler {
//read the ranges into the buffer
for (auto &rng : data->m_ranges) {
if (rng.first < m_file->getChannelCount()) {
memcpy(&data->m_data[sz], &fdata[fidx + rng.first], rng.second);
int start = fidx + rng.first;
memcpy(&data->m_data[sz], &fdata[start], rng.second);
sz += rng.second;
}
}
Expand Down Expand Up @@ -1233,14 +1234,21 @@ void V2FSEQFile::writeHeader() {
if (!m_sparseRanges.empty()) {
//make sure the sparse ranges fit, and then
//recalculate the channel count for in the fseq
std::vector<std::pair<uint32_t, uint32_t>> newRanges;
for (auto &a : m_sparseRanges) {
if (a.first + a.second > m_seqChannelCount) {
a.second = m_seqChannelCount - a.first;
if (a.first < m_seqChannelCount) {
if (a.first + a.second > m_seqChannelCount) {
a.second = m_seqChannelCount - a.first;
}
newRanges.push_back(a);
}
}
m_seqChannelCount = 0;
for (auto &a : m_sparseRanges) {
m_seqChannelCount += a.second;
m_sparseRanges = newRanges;
if (!m_sparseRanges.empty()) {
m_seqChannelCount = 0;
for (auto &a : m_sparseRanges) {
m_seqChannelCount += a.second;
}
}
}

Expand Down Expand Up @@ -1425,16 +1433,24 @@ void V2FSEQFile::dumpInfo(bool indent) {

void V2FSEQFile::prepareRead(const std::vector<std::pair<uint32_t, uint32_t>> &ranges) {
if (m_sparseRanges.empty()) {
m_rangesToRead = ranges;
m_rangesToRead.clear();
m_dataBlockSize = 0;
for (auto &rng : m_rangesToRead) {
for (auto rng : ranges) {
//make sure we don't read beyond the end of the sequence data
int toRead = rng.second;
if ((rng.first + toRead) > m_seqChannelCount) {
toRead = m_seqChannelCount - rng.first;
rng.second = toRead;

if (rng.first < m_seqChannelCount) {
if ((rng.first + toRead) > m_seqChannelCount) {
toRead = m_seqChannelCount - rng.first;
rng.second = toRead;
}
m_dataBlockSize += toRead;
m_rangesToRead.push_back(rng);
}
m_dataBlockSize += toRead;
}
if (m_dataBlockSize == 0) {
m_rangesToRead.push_back(std::pair<uint32_t, uint32_t>(0, getMaxChannel() + 1));
m_dataBlockSize = getMaxChannel();
}
} else if (m_compressionType != CompressionType::none) {
//with compression, there is no way to NOT read the entire frame of data, we'll just
Expand Down

0 comments on commit d635549

Please sign in to comment.