Skip to content
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

Fix UnicodeDecodeError #265

Open
wants to merge 2 commits into
base: master
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
20 changes: 11 additions & 9 deletions vint/encodings/decoder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import sys
import re
from typing import Dict, Any
from pprint import pformat
from pathlib import Path
from vint.encodings.decoding_strategy import DecodingStrategy


SCRIPTENCODING_PREFIX = bytearray('scriptencoding', encoding='ascii')



Expand Down Expand Up @@ -43,22 +43,24 @@ def _split_by_scriptencoding(bytes_seq):
start_index = 0
bytes_seq_and_loc_list = []

while True:
end_index = bytes_seq.find(SCRIPTENCODING_PREFIX, start_index + 1)
for m in re.finditer(b'^\s*(scriptencoding)', bytes_seq, re.MULTILINE):
end_index = m.start(1)

if end_index < 0:
end_index = max_end_index
if end_index == 0:
continue

bytes_seq_and_loc_list.append((
"{start_index}:{end_index}".format(start_index=start_index, end_index=end_index),
bytes_seq[start_index:end_index]
))
start_index = end_index

if end_index < max_end_index:
start_index = end_index
continue
bytes_seq_and_loc_list.append((
"{start_index}:{end_index}".format(start_index=start_index, end_index=max_end_index),
bytes_seq[start_index:max_end_index]
))

return bytes_seq_and_loc_list
return bytes_seq_and_loc_list


class EncodingDetectionError(Exception):
Expand Down
5 changes: 5 additions & 0 deletions vint/encodings/decoding_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def parse_script_encoding(cls, bytes_seq, debug_hint):
# type: (bytes, Dict[str, Any]) -> Optional[bytes]
try:
start_index = bytes_seq.index(SCRIPTENCODING_PREFIX)

if start_index != 0:
debug_hint['scriptencoding_error'] = '`scriptencoding` is comment or string'
return None

encoding_part_start_index = start_index + len(SCRIPTENCODING_PREFIX)

try:
Expand Down