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
On 32-bit PHP,
DateTime::getTimestamp()throwsValueErroron PHP 8.2 orDateRangeErroron PHP 8.3+ when the datetime cannot be represented as a native integer.WebDAV SEARCH requests can use broad datetime ranges for file search, for example media searches with dates before 1970 or after 2038. In that case
FileSearchBackend::castValue()currently throws andtransformSearchOperation()turns the error into:InvalidArgumentException: Invalid property value for {DAV:}getlastmodifiedThe whole SEARCH request then fails.
Fix
Move DATETIME casting into a small helper and handle out-of-range timestamps by clamping them to the platform-supported range:
0PHP_INT_MAXThis keeps the SEARCH request executable and matches the documented 32-bit date limitations.
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