Skip to content

Commit

Permalink
[fix] Self-extracting RAR files were not detected
Browse files Browse the repository at this point in the history
Fixes #108
  • Loading branch information
mxmlnkn committed Feb 23, 2024
1 parent 9faa29a commit de504ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion core/ratarmountcore/compressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,32 @@
}


def isRarFile(fileObject) -> bool:
# @see https://www.rarlab.com/technote.htm#rarsign
# > RAR 5.0 signature consists of 8 bytes: 0x52 0x61 0x72 0x21 0x1A 0x07 0x01 0x00.
# > You need to search for this signature in supposed archive from beginning and up to maximum SFX module size.
# > Just for comparison this is RAR 4.x 7 byte length signature: 0x52 0x61 0x72 0x21 0x1A 0x07 0x00.
# > Self-extracting module (SFX)
# > Any data preceding the archive signature. Self-extracting module size and contents is not defined.
# > At the moment of writing this documentation RAR assumes the maximum SFX module size to not exceed 1 MB,
# > but this value can be increased in the future.
oldPosition = fileObject.tell()
if fileObject.read(6) == b'Rar!\x1A\x07':
return True
if 'rarfile' in sys.modules:
fileObject.seek(oldPosition)
fileObject.seek(oldPosition)
if rarfile.is_rarfile_sfx(fileObject):
return True
return False


ARCHIVE_FORMATS: Dict[str, CompressionInfo] = {
'rar': CompressionInfo(
['rar'],
[],
[CompressionModuleInfo('rarfile', lambda x: rarfile.RarFile(x))],
lambda x: x.read(6) == b'Rar!\x1A\x07',
isRarFile,
),
'zip': CompressionInfo(
['zip'],
Expand Down
2 changes: 1 addition & 1 deletion core/ratarmountcore/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def openMountSource(fileOrPath: Union[str, IO[bytes]], **options) -> MountSource
)

try:
if 'rarfile' in sys.modules and rarfile.is_rarfile(fileOrPath):
if 'rarfile' in sys.modules and rarfile.is_rarfile_sfx(fileOrPath):
return RarMountSource(fileOrPath, **options)
except Exception as exception:
if printDebug >= 1:
Expand Down

0 comments on commit de504ed

Please sign in to comment.