@@ -887,6 +887,16 @@ ROOT::RResult<ROOT::RNTuple> ROOT::Internal::RMiniFileReader::GetNTupleBare(std:
887887
888888void ROOT::Internal::RMiniFileReader::ReadBuffer (void *buffer, size_t nbytes, std::uint64_t offset)
889889{
890+ TryReadBuffer (buffer, nbytes, offset).ThrowOnError ();
891+ }
892+
893+ ROOT::RResult<void > ROOT::Internal::RMiniFileReader::TryReadBuffer (void *buffer, size_t nbytes, std::uint64_t offset)
894+ {
895+ const auto ByteReadErr = [](std::size_t expected, std::size_t nread) {
896+ return R__FAIL (" invalid read (expected bytes: " + std::to_string (expected) + " , read: " + std::to_string (nread) +
897+ " )" );
898+ };
899+
890900 size_t nread;
891901 if (fMaxKeySize == 0 || nbytes <= fMaxKeySize ) {
892902 // Fast path: read single blob
@@ -900,7 +910,9 @@ void ROOT::Internal::RMiniFileReader::ReadBuffer(void *buffer, size_t nbytes, st
900910
901911 // Read first chunk
902912 nread = fRawFile ->ReadAt (bufCur, fMaxKeySize , offset);
903- R__ASSERT (nread == fMaxKeySize );
913+ if (nread != fMaxKeySize )
914+ return ByteReadErr (fMaxKeySize , nread);
915+
904916 // NOTE: we read the entire chunk in `bufCur`, but we only advance the pointer by `nbytesFirstChunk`,
905917 // since the last part of `bufCur` will later be overwritten by the next chunk's payload.
906918 // We do this to avoid a second ReadAt to read in the chunk offsets.
@@ -923,14 +935,19 @@ void ROOT::Internal::RMiniFileReader::ReadBuffer(void *buffer, size_t nbytes, st
923935 R__ASSERT (static_cast <size_t >(bufCur - reinterpret_cast <uint8_t *>(buffer)) <= nbytes - bytesToRead);
924936
925937 auto nbytesRead = fRawFile ->ReadAt (bufCur, bytesToRead, chunkOffset);
926- R__ASSERT (nbytesRead == bytesToRead);
938+ if (nbytesRead != bytesToRead)
939+ return ByteReadErr (bytesToRead, nbytesRead);
927940
928941 nread += bytesToRead;
929942 bufCur += bytesToRead;
930943 remainingBytes -= bytesToRead;
931944 } while (remainingBytes > 0 );
932945 }
933- R__ASSERT (nread == nbytes);
946+
947+ if (nread != nbytes)
948+ return ByteReadErr (nbytes, nread);
949+
950+ return RResult<void >::Success ();
934951}
935952
936953// //////////////////////////////////////////////////////////////////////////////
0 commit comments