Skip to content

Commit 7aca296

Browse files
authored
Merge pull request #40 from tonghuaroot/fix/ar-symtab-oob-26.01
ArHandler: backport 7-Zip 26.01 symbol table OOB read fix
2 parents 84036de + 713b113 commit 7aca296

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

CPP/7zip/Archive/ArHandler.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,11 @@ HRESULT CHandler::ParseLibSymbols(IInStream *stream, unsigned fileIndex)
473473
if (size - pos < tableSize || (tableSize & 7) != 0)
474474
continue;
475475
size_t namesStart = pos + tableSize;
476+
if (size - namesStart < 4)
477+
continue;
476478
const UInt32 namesSize = Get32(p.ConstData() + namesStart, be);
477479
namesStart += 4;
478-
if (namesStart > size || namesStart + namesSize != size)
480+
if (namesStart + namesSize != size)
479481
continue;
480482

481483
const UInt32 numSymbols = tableSize >> 3;
@@ -509,7 +511,7 @@ HRESULT CHandler::ParseLibSymbols(IInStream *stream, unsigned fileIndex)
509511

510512
for (UInt32 i = 0; i < numSymbols; i++)
511513
{
512-
const UInt32 offset = GetBe32(p + 4 + i * 4);
514+
const UInt32 offset = GetBe32(p + 4 + (size_t)i * 4);
513515
RINOK(AddFunc(offset, p, size, pos))
514516
}
515517
_type = kType_ALib;
@@ -534,11 +536,11 @@ HRESULT CHandler::ParseLibSymbols(IInStream *stream, unsigned fileIndex)
534536

535537
for (UInt32 i = 0; i < numSymbols; i++)
536538
{
537-
// index is 1-based. So 32-bit numSymbols field works as item[0]
538-
const UInt32 index = GetUi16(p + indexStart + i * 2);
539+
// index is 1-based. So 32-bit numMembers field works as item[0]
540+
const UInt32 index = GetUi16(p + indexStart + (size_t)i * 2);
539541
if (index == 0 || index > numMembers)
540542
return S_FALSE;
541-
const UInt32 offset = GetUi32(p + index * 4);
543+
const UInt32 offset = GetUi32(p + (size_t)index * 4);
542544
RINOK(AddFunc(offset, p, size, pos))
543545
}
544546
_type = kType_Lib;

0 commit comments

Comments
 (0)