Skip to content
This repository
Browse code

Further improvement of detection of encrypted RAR files.

  • Loading branch information...
commit eda7642af1f222cab256e4f3f592859e5f759105 1 parent cab42a4
shypike shypike authored

Showing 2 changed files with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. +8 7 sabnzbd/assembler.py
  2. +4 2 sabnzbd/utils/rarfile.py
15 sabnzbd/assembler.py
@@ -40,7 +40,7 @@
40 40 from sabnzbd.postproc import PostProcessor
41 41 import sabnzbd.downloader
42 42 from sabnzbd.utils.rarfile import RarFile, is_rarfile
43   -from sabnzbd.encoding import latin1
  43 +from sabnzbd.encoding import latin1, unicoder
44 44
45 45
46 46 #------------------------------------------------------------------------------
@@ -269,12 +269,13 @@ def ParseFilePacket(f, header):
269 269 return nothing
270 270
271 271
272   -def is_cloaked(names):
  272 +def is_cloaked(path, names):
273 273 """ Return True if this is likely to be a cloaked encrypted post """
  274 + fname = unicoder(os.path.split(path)[1]).lower()
274 275 for name in names:
275   - name = name.lower()
276   - if name.endswith('.rar') or 'password' in name:
277   - return len(names) < 3
  276 + name = unicoder(name.lower())
  277 + if fname == name or 'password' in name:
  278 + return True
278 279 return False
279 280
280 281
@@ -283,8 +284,8 @@ def check_encrypted_rar(nzo, filepath):
283 284 encrypted = False
284 285 if not nzo.password and cfg.pause_on_pwrar() and is_rarfile(filepath):
285 286 try:
286   - zf = RarFile(filepath)
287   - encrypted = zf.encrypted or is_cloaked(zf.namelist())
  287 + zf = RarFile(filepath, all_names=True)
  288 + encrypted = zf.encrypted or is_cloaked(filepath, zf.namelist())
288 289 if encrypted and int(nzo.encrypted) < 2:
289 290 nzo.encrypted = 1
290 291 else:
6 sabnzbd/utils/rarfile.py
@@ -124,9 +124,11 @@ def isdir(self):
124 124
125 125 class RarFile:
126 126 '''Rar archive handling.'''
127   - def __init__(self, rarfile, mode="r", charset='cp850', info_callback=None):
  127 + def __init__(self, rarfile, mode="r", charset='cp850', info_callback=None, all_names=False):
  128 + # 'all_names' = show names of 'split' files too
128 129 self.rarfile = rarfile
129 130 self.charset = charset
  131 + self.all_names = all_names
130 132
131 133 self.info_list = []
132 134 self.is_solid = 0
@@ -215,7 +217,7 @@ def _process_entry(self, item):
215 217 # RAR_BLOCK_NEWSUB has files too: CMT, RR
216 218 if item.type == RAR_BLOCK_FILE:
217 219 # use only first part
218   - if (item.flags & RAR_FILE_SPLIT_BEFORE) == 0:
  220 + if self.all_names or (item.flags & RAR_FILE_SPLIT_BEFORE) == 0:
219 221 # Always use Unix separators
220 222 item.filename = item.filename.replace('\\', '/')
221 223 item.unicode_filename = item.unicode_filename.replace(u'\\', u'/')

0 comments on commit eda7642

Please sign in to comment.
Something went wrong with that request. Please try again.