diff --git a/src/fseq/FSEQFile.cpp b/src/fseq/FSEQFile.cpp index 0f1bbb878..d8bd3df84 100644 --- a/src/fseq/FSEQFile.cpp +++ b/src/fseq/FSEQFile.cpp @@ -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; } } @@ -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> 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; + } } } @@ -1425,16 +1433,24 @@ void V2FSEQFile::dumpInfo(bool indent) { void V2FSEQFile::prepareRead(const std::vector> &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(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