Skip to content

INTEGRITY: Sync punycode code with Dumper Companion #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: integrity
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.dat
mysql_config.json
__pycache__
.DS_Store
11 changes: 7 additions & 4 deletions db_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from collections import defaultdict
import re

SPECIAL_SYMBOLS = '/":*|\\?%<>\x7f'

def db_connect():
base_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(base_dir, 'mysql_config.json')
Expand Down Expand Up @@ -158,7 +160,6 @@ def insert_file(file, detection, src, conn):
detection = 0
detection_type = f"{checktype}-{checksize}" if checktype != "None" else f"{checktype}"
if punycode_need_encode(file['name']):
print(encode_punycode(file['name']))
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())"
else:
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())"
Expand Down Expand Up @@ -204,7 +205,7 @@ def my_escape_string(s: str) -> str:
new_name += "\x81" + chr(0x80 + ord(char))
else:
new_name += char
return new_name
return escape_string(new_name)


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