-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove attacker-controlled error messages
Creates exceptions in the server code to be shared with the client via an identifying exit code. These exceptions are then reconstructed in the client. Refs #456 but does not completely fix it. Unexpected exceptions and progress descriptions are still passed in Containers.
- Loading branch information
Showing
6 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from typing import List, Optional | ||
|
||
|
||
class ConversionException(Exception): | ||
error_message = "Unspecificed error" | ||
error_code = -1 | ||
|
||
def __init__(self, error_message: Optional[str] = None) -> None: | ||
if error_message: | ||
self.error_message = error_message | ||
super().__init__(self.error_message) | ||
|
||
@classmethod | ||
def get_subclasses(cls) -> List[type["ConversionException"]]: | ||
subclasses = [cls] | ||
for subclass in cls.__subclasses__(): | ||
subclasses += subclass.get_subclasses() | ||
return subclasses | ||
|
||
|
||
class DocFormatUnsupported(ConversionException): | ||
error_code = 10 | ||
error_message = "The document format is not supported" | ||
|
||
|
||
class DocFormatUnsupportedHWPArm(DocFormatUnsupported): | ||
error_code = 15 | ||
error_message = "HWP / HWPX formats are not supported in ARM architectures" | ||
|
||
|
||
class DocFormatUnsupportedHWPQubes(DocFormatUnsupported): | ||
error_code = 16 | ||
error_message = "HWP / HWPX formats are not supported in Qubes" | ||
|
||
|
||
class LibreofficeFailure(ConversionException): | ||
error_code = 20 | ||
error_message = "Conversion to PDF with LibreOffice failed" | ||
|
||
|
||
class InvalidGMConversion(ConversionException): | ||
error_code = 30 | ||
error_message = "Invalid conversion (Graphics Magic)" | ||
|
||
def __init__(self, error_message: str) -> None: | ||
super(error_message) | ||
|
||
|
||
class PagesException(ConversionException): | ||
error_code = 40 | ||
|
||
|
||
class NoPageCountException(PagesException): | ||
error_code = 41 | ||
error_message = "Number of pages could not be extracted from PDF" | ||
|
||
|
||
class PDFtoPPMException(ConversionException): | ||
error_code = 50 | ||
error_message = f"Error converting PDF to Pixels (pdftoppm)" | ||
|
||
|
||
class PDFtoPPMInvalidHeader(PDFtoPPMException): | ||
error_code = 51 | ||
error_message = "Error converting PDF to Pixels (Invalid PPM header)" | ||
|
||
|
||
class PDFtoPPMInvalidDepth(PDFtoPPMException): | ||
error_code = 52 | ||
error_message = "Error converting PDF to Pixels (Invalid PPM depth)" | ||
|
||
|
||
def exception_from_error_code(error_code: int) -> Optional[ConversionException]: | ||
"""returns the conversion exception corresponding to the error code""" | ||
for cls in ConversionException.get_subclasses(): | ||
if cls.error_code == error_code: | ||
return cls() | ||
raise ValueError(f"Unknown error code '{error_code}'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters