From a8f0423e20410c9da0369508468a3c69bf2befa0 Mon Sep 17 00:00:00 2001 From: Iven Ahrens <25607353+Ahnz@users.noreply.github.com> Date: Wed, 13 May 2026 21:16:36 +0200 Subject: [PATCH] fix(dav): handle out-of-range datetime search values 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> --- apps/dav/lib/Files/FileSearchBackend.php | 30 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php index 206d812bd4333..7c51b36976bb0 100644 --- a/apps/dav/lib/Files/FileSearchBackend.php +++ b/apps/dav/lib/Files/FileSearchBackend.php @@ -505,16 +505,36 @@ private function castValue(SearchPropertyDefinition $property, $value) { case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: return 0 + $value; case SearchPropertyDefinition::DATATYPE_DATETIME: - if (is_numeric($value)) { - return max(0, 0 + $value); - } - $date = \DateTime::createFromFormat(\DateTimeInterface::ATOM, (string)$value); - return ($date instanceof \DateTime && $date->getTimestamp() !== false) ? $date->getTimestamp() : 0; + return $this->castDateTimeValue($value); default: return $value; } } + private function castDateTimeValue($value) { + if (is_numeric($value)) { + return max(0, 0 + $value); + } + + $date = \DateTime::createFromFormat(\DateTimeInterface::ATOM, (string)$value); + if (!$date instanceof \DateTime) { + return 0; + } + + try { + return $date->getTimestamp(); + } catch (\Error $e) { + if (!$e instanceof \ValueError && !is_a($e, 'DateRangeError')) { + throw $e; + } + + // On 32-bit PHP, getTimestamp() fails for dates outside the + // representable integer range. Clamp broad search bounds instead of + // failing the whole WebDAV SEARCH request. + return (int) $date->format("Y") >= 2038 ? PHP_INT_MAX : 0; + } + } + /** * Get a specific property from the were clause */