fix(dav): handle out-of-range datetime values in file search#60364
Open
Ahnz wants to merge 1 commit into
Open
Conversation
On 32-bit PHP, DateTime::getTimestamp() can throw ValueError or DateRangeError when a WebDAV SEARCH datetime value is outside the platform's representable integer timestamp range. This can happen when clients send broad date ranges for file search, for example dates before 1970 or after 2038. The exception is currently converted to an InvalidArgumentException and aborts the whole SEARCH request. Clamp unrepresentable datetime values to the nearest platform boundary instead, so the SEARCH request can still be executed. Signed-off-by: Iven Ahrens <25607353+Ahnz@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some DAV SEARCH requests use very broad datetime bounds for file search. For example, media searches may use a range such as
0001-01-01to4001-01-01to search across all possible media dates.On 32-bit PHP, those bounds are outside the timestamp range that can be represented as a native integer:
When
FileSearchBackend::castValue()converts such a datetime withDateTime::getTimestamp(), PHP throws because the resulting timestamp does not fit into a 32-bit integer. PHP 8.2 throwsValueError; PHP 8.3 and newer throwDateRangeError.transformSearchOperation()then turns the error into:InvalidArgumentException: Invalid property value for {DAV:}getlastmodifiedThe whole SEARCH request fails.
Fix
Move DATETIME casting into a small helper and handle datetime values that cannot be represented on the current platform by clamping them to the platform-supported range:
0PHP_INT_MAXThis preserves the existing behavior for datetime values that can be represented on the current platform. The added handling only applies when
DateTime::getTimestamp()cannot represent the value.This does not extend the supported date range on 32-bit PHP. It keeps the SEARCH request executable by mapping out-of-range search bounds to the nearest documented 32-bit boundary.
Notes
The fix is generic for DAV datetime search values and is not specific to the iOS client.
Related issues:
Testing
Invalid property value for {DAV:}getlastmodifiedno longer appears innextcloud.logphp -l apps/dav/lib/Files/FileSearchBackend.phpChecklist
AI