diff --git a/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php b/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php
index 70ee07a1ebe047a93d9d6c9bfc63d00a267ff49a..4ed1bb82d7d4b700a005113d2e38f3f6a2f67b37 100644
--- a/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php
+++ b/core/lib/Drupal/Core/File/MimeType/ExtensionMimeTypeGuesser.php
@@ -915,7 +915,9 @@ public function guessMimeType($path): ?string {
     // then iterate over the file parts, trying to find a match.
     // For 'my.awesome.image.jpeg', we try: 'awesome.image.jpeg', then
     // 'image.jpeg', then 'jpeg'.
-    while (array_shift($file_parts)) {
+    // We explicitly check for NULL because that indicates that the array is
+    // empty.
+    while (array_shift($file_parts) !== NULL) {
       $extension = strtolower(implode('.', $file_parts));
       if (isset($this->mapping['extensions'][$extension])) {
         return $this->mapping['mimetypes'][$this->mapping['extensions'][$extension]];
diff --git a/core/tests/Drupal/KernelTests/Core/File/MimeTypeTest.php b/core/tests/Drupal/KernelTests/Core/File/MimeTypeTest.php
index 9136dfeede29abacba0127bacebdf5b55d451497..653902e9f58cca520a64ceab9b75c0858cda808c 100644
--- a/core/tests/Drupal/KernelTests/Core/File/MimeTypeTest.php
+++ b/core/tests/Drupal/KernelTests/Core/File/MimeTypeTest.php
@@ -44,6 +44,8 @@ public function testFileMimeTypeDetection(): void {
       'foobar.z' => 'application/x-compress',
       'foobar.tar' => 'application/x-tar',
       'foobar.tar.z' => 'application/x-tarz',
+      'foobar.0.zip' => 'application/zip',
+      'foobar..zip' => 'application/zip',
     ];
 
     $guesser = $this->container->get('file.mime_type.guesser');