Page 1 of 1

Queue stalls permanently if unable to create _UNPACK_ directories in v0.4.6

Posted: February 17th, 2009, 8:59 am
by WhiteSea
I found an issue on my Linux system where the queue will stall and start to back up if SABnzbd is unable to create the _UNPACK_ directory due to illegal characters. In my case this was a "?".

It would appear that only filenames are sanitised and not the directory structure. I have applied the following quick fix in misc.py and have added sanitize_dirname immediately following sanitise_pathname. I have also highlighted in red the single change required in CreateAllDirs.

This is just a quick fix and I have not gone through the code in any great depth, as no doubt you will want to revise this and incorporate into a future release.

Regards,
Craig.

################################################################################
# sanitize_dirname                                                            #
################################################################################
def sanitize_dirname(name):
    """ Return pathname with illegal chars converted to legal ones
    """
    illegal = r'\/?*:;|"'
    legal   = r'++{}!@--#`'

    repl = sabnzbd.REPLACE_ILLEGAL
    lst = []
    for ch in name.strip():
        if ch in illegal:
            if repl:
                ch = legal[illegal.find(ch)]
                lst.append(ch)
        else:
            lst.append(ch)
    name = ''.join(lst)

    if not name:
        name = 'unknown'

    return name

################################################################################
# DirPermissions                                                               #
################################################################################
def CreateAllDirs(path, umask=None):
    """ Create all required path elements and set umask on all
        Return True if last elelent could be made or exists """
    result = True
    if os.name == 'nt':
        try:
            os.makedirs(path)
        except:
            result = False
    else:
        list = []
        list.extend(path.split('/'))
        path = ''
        for d in list:
            if d:
                path += '/' + sanitize_dirname(d)
   
             if not os.path.exists(path):
                    try:
                        os.mkdir(path)
                        result = True
                    except:
                        result = False
                try:
                    if umask: os.chmod(path, int(umask, 8) | 0700)
                except:
                    pass
    return result

Re: Queue stalls permanently if unable to create _UNPACK_ directories in v0.4.6

Posted: February 17th, 2009, 9:24 am
by shypike
Odd, the only folder name that's created comes from either the NZB name
or the description in an RSS feed.
Both of these are filtered.
Can you give an example of how this odd folder name entered SABnzbd?
Please email to bugs@sabnzbd.org

Re: Queue stalls permanently if unable to create _UNPACK_ directories in v0.4.6

Posted: February 17th, 2009, 12:03 pm
by shypike
Received your info.
The question that remains is: how did you enter this NZB file into SABnzbd?
It cannot have been a locally stored file. Did you get it from an RSS feed?
If so, can you send me the URL?

Re: Queue stalls permanently if unable to create _UNPACK_ directories in v0.4.6

Posted: February 17th, 2009, 7:13 pm
by switch
I had a chat with WhiteSea earlier and resolved the issue, see http://trac2.assembla.com/SABnzbd/changeset/2202