Docker Community Forums

Share and learn in the Docker community.

In an arm32 image-based container, readdir returns EOVERFLOW when directory is empty

Upon calling readdir function in a C program within an arm32 container executing on x64 Ubuntu host, the call returns EOVERFLOW for empty directories (e.g., /mnt, /media) instead of returning 0.

Have others observed this issue? Is this a configuration issue or a bug in Docker?

Versions:

  • Guest: debian:buster- backports@sha256:8f27850df2144df1598b5c76b213616ecaab08e804a6d84ddace1455d8cbd9f0
  • Host: Ubuntu 19.10, amd64,
  • Docker version: 19.03.6-0ubuntu1~19.10.1
  • Qemu version: 1:4.0+dfsg-0ubuntu9.6

Repro steps:

  1. Build an image named crystal-for-buster-armhf:v1 based on Debian Buster for arm32 using the Dockerfile and build.sh script available here.
  2. Start a container based on this image.
  3. Compile and build the below program.
  4. Execute the resulting executable with a directory name as a command line argument.
#define _POSIX_SOURCE
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#undef _POSIX_SOURCE
#include <stdio.h>

main(int argc, char* argv[]) {
  DIR *dir;
  struct dirent *entry;

  if ((dir = opendir(argv[1])) == NULL)
    perror("opendir() error");
  else {
    puts("contents:");
    while (1) {
      errno = 0;
      entry = readdir(dir);
      if (entry == NULL) {
        printf("Errno: %d   EOVERFLOW: %d\n", errno, EOVERFLOW);
        break;
      }
      printf("  %s\n", entry->d_name);
    }
    closedir(dir);
  }
}

As pointed out on Stack Overflow, this was an issue of using 32-bit numbers to access inode numbers that don’t fit into 32-bit numbers. Resolved :slight_smile: