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 */