Skip to content

Commit

Permalink
Merge pull request #42 from ddash-ct/datetime-errors
Browse files Browse the repository at this point in the history
Catch OSError for DateTime constructs and raise as ConstructError
  • Loading branch information
dc3-tsd authored Nov 18, 2023
2 parents 837c8fc + bd4265b commit aa27546
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.


## [Unreleased]

### Changed
- Catch OSError from DateTime related constructs and raise as ConstructError


## [3.13.0] - 2023-07-17

### Added
Expand Down
5 changes: 4 additions & 1 deletion mwcp/utils/construct/datetime_.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def __init__(self, subcon, tz=None):
self._tz = tz

def _decode(self, obj, context, path):
return datetime.datetime.fromtimestamp(obj, tz=self._tz).isoformat()
try:
return datetime.datetime.fromtimestamp(obj, tz=self._tz).isoformat()
except OSError as e:
raise construct.ConstructError(e)


# Add common helpers
Expand Down
20 changes: 13 additions & 7 deletions mwcp/utils/construct/windows_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,13 @@ def __init__(self, subcon, tzinfo=None):
self._tzinfo = tzinfo

def _decode(self, obj, context, path):
return datetime.datetime(
obj.wYear, obj.wMonth, obj.wDay, obj.wHour, obj.wMinute, obj.wSecond, obj.wMilliseconds * 1000,
tzinfo=self._tzinfo
).isoformat()
try:
return datetime.datetime(
obj.wYear, obj.wMonth, obj.wDay, obj.wHour, obj.wMinute, obj.wSecond, obj.wMilliseconds * 1000,
tzinfo=self._tzinfo
).isoformat()
except OSError as e:
raise construct.ConstructError(e)


# Add common helpers
Expand Down Expand Up @@ -356,9 +359,12 @@ def __init__(self, subcon, tz=None):
self._tz = tz

def _decode(self, obj, context, path):
return datetime.datetime.fromtimestamp(
(obj - EPOCH_AS_FILETIME) / HUNDREDS_OF_NANOSECONDS, tz=self._tz
).isoformat()
try:
return datetime.datetime.fromtimestamp(
(obj - EPOCH_AS_FILETIME) / HUNDREDS_OF_NANOSECONDS, tz=self._tz
).isoformat()
except OSError as e:
raise construct.ConstructError(e)


# Add common helpers
Expand Down

0 comments on commit aa27546

Please sign in to comment.