Skip to content

Commit 83dda53

Browse files
committed
INTEGRITY: Sync punycode code with Dumper Companion
1 parent 88aa0ed commit 83dda53

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.dat
22
mysql_config.json
33
__pycache__
4+
.DS_Store

db_functions.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from collections import defaultdict
1010
import re
1111

12+
SPECIAL_SYMBOLS = '/":*|\\?%<>\x7f'
13+
1214
def db_connect():
1315
base_dir = os.path.dirname(os.path.abspath(__file__))
1416
config_path = os.path.join(base_dir, 'mysql_config.json')
@@ -158,7 +160,6 @@ def insert_file(file, detection, src, conn):
158160
detection = 0
159161
detection_type = f"{checktype}-{checksize}" if checktype != "None" else f"{checktype}"
160162
if punycode_need_encode(file['name']):
161-
print(encode_punycode(file['name']))
162163
query = f"INSERT INTO file (name, size, checksum, fileset, detection, detection_type, `timestamp`) VALUES ('{encode_punycode(file['name'])}', '{file['size']}', '{checksum}', @fileset_last, {detection}, '{detection_type}', NOW())"
163164
else:
164165
query = f"INSERT INTO file (name, size, checksum, fileset, detection, detection_type, `timestamp`) VALUES ('{escape_string(file['name'])}', '{file['size']}', '{checksum}', @fileset_last, {detection}, '{detection_type}', NOW())"
@@ -204,7 +205,7 @@ def my_escape_string(s: str) -> str:
204205
new_name += "\x81" + chr(0x80 + ord(char))
205206
else:
206207
new_name += char
207-
return new_name
208+
return escape_string(new_name)
208209

209210

210211
def encode_punycode(orig):
@@ -232,7 +233,9 @@ def punycode_need_encode(orig):
232233
- contains a char that should be escaped or
233234
- ends with a dot or a space.
234235
"""
235-
if orig != escape_string(orig):
236+
if not all(
237+
(0x20 <= ord(c) < 0x80) and
238+
c not in SPECIAL_SYMBOLS for c in orig):
236239
return True
237240
if orig[-1] in " .":
238241
return True
@@ -990,4 +993,4 @@ def add_usercount(fileset, conn):
990993
cursor.execute(f"SELECT user_count from fileset WHERE id = {fileset}")
991994
count = cursor.fetchone()['user_count']
992995
if count >= 3:
993-
cursor.execute(f"UPDATE fileset SET status = 'ReadyForReview' WHERE id = {fileset}")
996+
cursor.execute(f"UPDATE fileset SET status = 'ReadyForReview' WHERE id = {fileset}")

0 commit comments

Comments
 (0)