mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-03 06:02:29 -06:00
Avoid out-of-bounds access
This happens when the `index` is a negative number. Added `Q_ASSERT()` to catch coding errors at debug run time. PR #17953.
This commit is contained in:
@@ -241,6 +241,11 @@ Path TorrentInfo::filePath(const int index) const
|
||||
{
|
||||
if (!isValid()) return {};
|
||||
|
||||
Q_ASSERT(index >= 0);
|
||||
Q_ASSERT(index < m_nativeIndexes.size());
|
||||
if ((index < 0) || (index >= m_nativeIndexes.size()))
|
||||
return {};
|
||||
|
||||
return Path(m_nativeInfo->orig_files().file_path(m_nativeIndexes[index]));
|
||||
}
|
||||
|
||||
@@ -258,6 +263,11 @@ qlonglong TorrentInfo::fileSize(const int index) const
|
||||
{
|
||||
if (!isValid()) return -1;
|
||||
|
||||
Q_ASSERT(index >= 0);
|
||||
Q_ASSERT(index < m_nativeIndexes.size());
|
||||
if ((index < 0) || (index >= m_nativeIndexes.size()))
|
||||
return -1;
|
||||
|
||||
return m_nativeInfo->orig_files().file_size(m_nativeIndexes[index]);
|
||||
}
|
||||
|
||||
@@ -265,6 +275,11 @@ qlonglong TorrentInfo::fileOffset(const int index) const
|
||||
{
|
||||
if (!isValid()) return -1;
|
||||
|
||||
Q_ASSERT(index >= 0);
|
||||
Q_ASSERT(index < m_nativeIndexes.size());
|
||||
if ((index < 0) || (index >= m_nativeIndexes.size()))
|
||||
return -1;
|
||||
|
||||
return m_nativeInfo->orig_files().file_offset(m_nativeIndexes[index]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user