dfvfs
dfvfs copied to clipboard
Exception Message Truncation on Windows
On Windows, dfvfs Exceptions can contain messages with returns but without the new line character. This can lead to message truncation when exceptions are thrown.
If I run the following on an image that errors out during the source scanner's Scan:
import sys
from dfvfs.helpers import source_scanner
def main():
source = sys.argv[1]
scan_path_spec = None
scanner = source_scanner.SourceScanner()
scan_context = source_scanner.SourceScannerContext()
scan_context.OpenSourcePath(source)
try:
scanner.Scan(
scan_context,
scan_path_spec=scan_path_spec
)
except Exception as error:
print("---------------------------------------------")
print("Error Message Without Replacing Returns")
print(r'print(error)')
print("---------------------------------------------")
print(error)
print("")
print("")
print("---------------------------------------------")
print("Error Message With Replacing Returns")
print(r'print(str(error).replace("\r", "\n"))')
print("---------------------------------------------")
print(str(error).replace("\r", "\n"))
print("")
print("")
print("---------------------------------------------")
print("On Raise")
print(r'raise error')
print("---------------------------------------------")
raise error
if __name__ == "__main__":
main()
I get the following output:
---------------------------------------------
Error Message Without Replacing Returns
print(error)
---------------------------------------------
libbde_volume_open_file_io_handle: unable to read from file IO handle.ntry_read: unsupported FVE metadata entry version.
---------------------------------------------
Error Message With Replacing Returns
print(str(error).replace("\r", "\n"))
---------------------------------------------
pybde_volume_open_file_object: unable to open volume. libbde_metadata_entry_read: unsupported FVE metadata entry version.
libbde_metadata_read_entries: unable to read metadata entry.
libbde_metadata_read_block: unable to read metadata header.
libbde_volume_open_read: unable to read primary metadata block.
libbde_volume_open_file_io_handle: unable to read from file IO handle.
---------------------------------------------
On Raise
raise error
---------------------------------------------
Traceback (most recent call last):
File "error_truncation.py", line 40, in <module>
main()
File "error_truncation.py", line 36, in main
raise error
libbde_volume_open_file_io_handle: unable to read from file IO handle.etadata_entry_read: unsupported FVE metadata entry version.
It has helped me out in some situations to see the extended message, so, I thought I would put it here. Hope this info might help someone else.
The end of line on windows should be '\r\n' https://github.com/libyal/libcerror/blob/master/libcerror/libcerror_error.c#L757
The library error is then transformed into a Python error string https://github.com/libyal/libbde/blob/master/pybde/pybde_error.c#L145
I'll see if I can reproduce this and see if it is some underlying issue.
@devgc which version of libbde did you use in your tests?
I believe it was 20190102. Generally I install from what is available at https://github.com/log2timeline/l2tbinaries/tree/master/win64. But since this error, I have updated to a newer version.
I'll need to have a closer look at this when time permits.