From dc073b2afdb2c4bd8089cfb87e2066ffa65fb70e Mon Sep 17 00:00:00 2001 From: Gao Xiang Date: Fri, 18 Oct 2024 12:47:03 +0800 Subject: [PATCH] [bugfix] workaround if some SegmentMapping refers to end of tar Currently it could happen on EROFS meta indexes. Signed-off-by: Gao Xiang --- src/overlaybd/lsmt/file.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/overlaybd/lsmt/file.cpp b/src/overlaybd/lsmt/file.cpp index d8336b3a..53bbfb4a 100644 --- a/src/overlaybd/lsmt/file.cpp +++ b/src/overlaybd/lsmt/file.cpp @@ -573,9 +573,19 @@ class LSMTReadOnlyFile : public IFileRW { // LOG_DEBUG("offset: `, length: `", m.moffset, size); ssize_t ret = m_files[m.tag]->pread(buf, size, m.moffset * ALIGNMENT); if (ret < size) { - LOG_ERRNO_RETURN(0, (int)ret, - "failed to read from `-th file ( ` pread return: ` < size: `)", - m.tag, m_files[m.tag], ret, size); + if (ret < 0) { + LOG_ERRNO_RETURN(0, -1, + "failed to read from `-th file ( ` pread return: ` < size: `)", + m.tag, m_files[m.tag], ret, size); + } + size_t ret2 = m_files[m.tag]->pread((char *)buf + ret, size - ret, m.moffset * ALIGNMENT + ret); + if (ret2) { + LOG_ERRNO_RETURN(0, (int)ret, + "failed to read from `-th file ( ` pread return: ` < size: `)", + m.tag, m_files[m.tag], ret, size); + } else { + memset((char *)buf + ret, 0, size - ret); + } } lsmt_io_size += ret; lsmt_io_cnt++;