Skip to content

Commit

Permalink
changed/fixed: add some sanity checks to rar code to avoid crashes wi…
Browse files Browse the repository at this point in the history
…th corrupt archives.
  • Loading branch information
spiff committed Nov 15, 2011
1 parent dab7e1a commit f0b4837
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/UnrarXLib/rar.cpp
Expand Up @@ -345,6 +345,13 @@ int urarlib_list(char *rarfile, ArchiveList_struct **ppList, char *libpassword,
if (!*ppList)
*ppList = pCurr;
pCurr->item.NameSize = strlen(pArc->NewLhd.FileName);
// sanity check - if it fails the archive is likely corrupt
if (pCurr->item.NameSize > NM)
{
File::RemoveCreated();
return 0;
}

pCurr->item.Name = (char *)malloc(pCurr->item.NameSize + 1);
strcpy(pCurr->item.Name, pArc->NewLhd.FileName);
pCurr->item.NameW = (wchar *)malloc((pCurr->item.NameSize + 1)*sizeof(wchar));
Expand All @@ -365,6 +372,11 @@ int urarlib_list(char *rarfile, ArchiveList_struct **ppList, char *libpassword,
break;
}
iOffset = pArc->NextBlockPos;
if (iOffset > pArc->FileLength())
{
File::RemoveCreated();
return 0;
}
pArc->SeekToNext();
}
if (pCmd->VolSize!=0 && ((pArc->NewLhd.Flags & LHD_SPLIT_AFTER) || (pArc->GetHeaderType()==ENDARC_HEAD && (pArc->EndArcHead.Flags & EARC_NEXT_VOLUME)!=0)))
Expand Down
3 changes: 3 additions & 0 deletions xbmc/filesystem/RarDirectory.cpp
Expand Up @@ -71,7 +71,10 @@ namespace XFILE
return( true);
}
else
{
CLog::Log(LOGWARNING,"%s: rar lib returned no files in archive %s, likely corrupt",__FUNCTION__,strArchive.c_str());
return( false );
}
}

bool CRarDirectory::Exists(const char* strPath)
Expand Down

0 comments on commit f0b4837

Please sign in to comment.