--- file.c.origin	2023-06-26 04:26:23.029935619 +0000
+++ file.c	2023-06-26 04:25:22.414335201 +0000
@@ -4472,7 +4472,7 @@
            such as /dev/fd/5.
            Fallback to the emulated approach in either of those cases. */
         if (errno == ENOTDIR ||
-            (errno == ENOENT && rb_file_exist_p(0, unresolved_path))) {
+            (errno == ENOENT && rb_file_exist_p(0, unresolved_path)) || errno == EINVAL) {
             return rb_check_realpath_emulate(basedir, path, origenc, mode);
 
         }
