Fixed filesplit corner case infinite loop
authorDaniel Garcia Moreno <danigm@wadobo.com>
Tue, 16 Jul 2013 08:24:59 +0000 (10:24 +0200)
committerDaniel Garcia Moreno <danigm@wadobo.com>
Tue, 16 Jul 2013 08:24:59 +0000 (10:24 +0200)
filesplit.py

index b06d99a..ef7129d 100644 (file)
@@ -63,7 +63,7 @@ def split_file(separator, prefix, input_file, new_file_func=None):
             # corner case: separator is between this buf and next one. In this
             # case, we write to current output everything before that and
             # iterate
-            if separator[0] in buf[-sep_len:]:
+            if len(buf) > sep_len and separator[0] in buf[-sep_len:]:
                 output.write(buf[:-sep_len])
                 buf = buf[-sep_len:]
                 continue