mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Error out - when user tries to load a binary file in the Query Editor.
This commit is contained in:
parent
db79f3ff3d
commit
f4938beb3c
@ -1115,10 +1115,27 @@ def load_file():
|
||||
)
|
||||
file_data = None
|
||||
|
||||
# check if file type is text or binary
|
||||
textchars = bytearray(
|
||||
{7, 8, 9, 10, 12, 13, 27} | set(
|
||||
range(0x20, 0x100)
|
||||
) - {0x7f})
|
||||
|
||||
is_binary_string = lambda bytes: bool(
|
||||
bytes.translate(None, textchars)
|
||||
)
|
||||
|
||||
# read file
|
||||
try:
|
||||
with open(file_path, 'r') as myfile:
|
||||
file_data = myfile.read()
|
||||
with open(file_path, 'rb') as fileObj:
|
||||
is_binary = is_binary_string(fileObj.read(1024))
|
||||
if not is_binary:
|
||||
fileObj.seek(0)
|
||||
file_data = fileObj.read()
|
||||
else:
|
||||
return internal_server_error(
|
||||
errormsg=gettext("File type not supported")
|
||||
)
|
||||
except IOError as e:
|
||||
# we don't want to expose real path of file
|
||||
# so only show error message.
|
||||
|
Loading…
Reference in New Issue
Block a user