owasp-amass/amass · error

error reading the first 512 bytes from %s: %s

Error message

error reading the first 512 bytes from %s: %s

What it means

To decide whether the wordlist is gzipped, getGzipReader reads the first 512 bytes for content-type sniffing; this error is returned if that read fails. A successful os.Open followed by a failed Read usually indicates an I/O problem rather than a missing file.

Source

Thrown at config/wordlist.go:125

}

func getGzipReader(file *os.File, absPath string) (*gzip.Reader, error) {
	finfo, err := file.Stat()
	if err != nil {
		return nil, err
	}

	if finfo.Size() < 512 {
		return nil, errors.New("file cannot be checked for compression")
	}

	// We need to determine if this is a gzipped file or a plain text file, so we
	// first read the first 512 bytes to pass them down to http.DetectContentType
	// for mime detection. The file is rewinded before passing it along to the
	// next reader
	head := make([]byte, 512)
	if _, err = file.Read(head); err != nil {
		return nil, fmt.Errorf("error reading the first 512 bytes from %s: %s", absPath, err)
	}
	if _, err = file.Seek(0, 0); err != nil {
		return nil, fmt.Errorf("error rewinding the file %s: %s", absPath, err)
	}

	// Read the file as gzip if it's actually compressed
	if mt := http.DetectContentType(head); mt == "application/gzip" || mt == "application/x-gzip" {
		gzReader, err := gzip.NewReader(file)
		if err != nil {
			return nil, fmt.Errorf("error gz-reading the file %s: %v", absPath, err)
		}

		return gzReader, nil
	}

	return nil, fmt.Errorf("%s is not compressed", absPath)
}

View on GitHub (pinned to 79299dce87)

Solutions

  1. Re-run after confirming the file is a regular readable file (file <path>)
  2. Replace a corrupted wordlist file
  3. Check disk/filesystem health if errors persist

Example fix

// before
cmd := exec.Command(tool, "--wordlist", "/dev/random")
// after
cmd := exec.Command(tool, "--wordlist", "/usr/share/wordlists/common.txt")
Defensive patterns

Strategy: validation

Validate before calling

info, err := os.Stat(path)
if err == nil && !info.Mode().IsRegular() { return errors.New("wordlist must be a regular file") }

Try / catch

words, err := GetListFromFile(p)
if err != nil {
  if strings.HasPrefix(err.Error(), "error reading the first 512 bytes") {
    // verify file integrity / replace the wordlist
  }
  return err
}

Prevention

When it happens

Trigger: file.Read(head) errors inside getGzipReader (called from GetListFromFile): e.g. file is a special device, an I/O error occurs, or the fd is bad on exotic filesystems.

Common situations: Corrupt storage, reading from /proc-like pseudo files that error on read, or race conditions where the file was truncated/deleted mid-read.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06). Data as JSON: /api/errors/7af0556fb76455ad. Report an issue: GitHub.