Replace armor guards that indicate isolated output

This commit is contained in:
deeplow 2023-08-07 13:04:37 +01:00
parent a0bcd12635
commit 9ec9cc5f87
No known key found for this signature in database
GPG key ID: 577982871529A52A
3 changed files with 20 additions and 10 deletions

View file

@ -11,8 +11,10 @@ from ..util import replace_control_chars
log = logging.getLogger(__name__)
MAX_CONVERSION_LOG_CHARS = 150 * 50 # up to ~150 lines of 50 characters
CONVERSION_LOG_START = "-----CONVERSION LOG START-----"
CONVERSION_LOG_END = "-----CONVERSION LOG END-----"
DOC_TO_PIXELS_LOG_START = "----- DOC TO PIXELS LOG START -----"
DOC_TO_PIXELS_LOG_END = "----- DOC TO PIXELS LOG END -----"
PIXELS_TO_PDF_LOG_START = "----- PIXELS TO PDF LOG START -----"
PIXELS_TO_PDF_LOG_END = "----- PIXELS TO PDF LOG END -----"
class IsolationProvider(ABC):
@ -90,8 +92,8 @@ class IsolationProvider(ABC):
conversion_string = replace_control_chars(untrusted_conversion_str)
# Add armor (gpg-style)
armor_start = f"{CONVERSION_LOG_START}\n"
armor_end = CONVERSION_LOG_END
armor_start = f"{DOC_TO_PIXELS_LOG_START}\n"
armor_end = DOC_TO_PIXELS_LOG_END
return armor_start + conversion_string + armor_end

View file

@ -18,7 +18,12 @@ from ..util import (
get_tmp_dir,
replace_control_chars,
)
from .base import MAX_CONVERSION_LOG_CHARS, IsolationProvider
from .base import (
MAX_CONVERSION_LOG_CHARS,
PIXELS_TO_PDF_LOG_END,
PIXELS_TO_PDF_LOG_START,
IsolationProvider,
)
# Define startupinfo for subprocesses
if platform.system() == "Windows":
@ -339,9 +344,12 @@ class Container(IsolationProvider):
if getattr(sys, "dangerzone_dev", False):
log_path = safe_dir / "captured_output.txt"
if log_path.exists(): # If first stage failed this may not exist
with open(log_path, "r", encoding="ascii", errors="replace") as f:
untrusted_log = f.read(MAX_CONVERSION_LOG_CHARS)
text = f"Container output: (pixels to PDF)\n{self.sanitize_conversion_str(untrusted_log)}"
text = (
f"Container output: (pixels to PDF)\n"
f"{PIXELS_TO_PDF_LOG_START}{f.read()}{PIXELS_TO_PDF_LOG_END}"
)
log.info(text)
return success

@ -1 +1 @@
Subproject commit 51419aa36bd4701927d1610fb544e18a4692f1db
Subproject commit 0068ffcb67f45fe9e3a082649493b7c8db5d1473