diff --git a/partridge/utilities.py b/partridge/utilities.py
index <HASH>..<HASH> 100644
--- a/partridge/utilities.py
+++ b/partridge/utilities.py
@@ -47,12 +47,15 @@ def remove_node_attributes(G, attributes):
     return G
 
 
-def detect_encoding(f):
+def detect_encoding(f, limit=100):
     u = UniversalDetector()
     for line in f:
         line = bytearray(line)
         u.feed(line)
-        if u.done:
+
+        limit -= 1
+        if u.done or limit < 1:
             break
+
     u.close()
     return u.result['encoding']
Limit the number of lines read to detect character encoding