projectdiscovery/nuclei · error
file %q exceeds max read size of %d bytes
Error message
file %q exceeds max read size of %d bytes
What it means
Thrown on the streaming path of readFile when the file is larger than the read cap. The library opens the file and wraps it in io.LimitReader(f, maxBytes+1); reading maxBytes+1 bytes proves the file exceeds the limit, and the error reports the offending path and the cap. maxBytes defaults to DefaultMaxReadBytes (10 MiB) when the caller passes 0 or a negative value.
Source
Thrown at pkg/js/libs/smbsession/session.go:241
}
if err := ops.UseShare(share); err != nil {
return "", fmt.Errorf("mount share %q: %w", share, err)
}
// Prefer streaming Open+LimitReader when the backend supports it (tests /
// future goimpacket Open). Fall back to Cat for the stock client.
if opener, ok := ops.(shareOpener); ok {
f, err := opener.Open(normalized)
if err != nil {
return "", err
}
defer func() { _ = f.Close() }()
limited := io.LimitReader(f, maxBytes+1)
body, err := io.ReadAll(limited)
if err != nil {
return "", err
}
if int64(len(body)) > maxBytes {
return "", fmt.Errorf("file %q exceeds max read size of %d bytes", normalized, maxBytes)
}
return string(body), nil
}
body, err := ops.Cat(normalized)
if err != nil {
return "", err
}
if int64(len(body)) > maxBytes {
return "", fmt.Errorf("file %q exceeds max read size of %d bytes", normalized, maxBytes)
}
return body, nil
}
func listTree(ops shareBackend, share, root string, maxDepth, maxEntries int) ([]Entry, error) {
if err := RequireShareName(share); err != nil {
return nil, err
}
if maxDepth <= 0 {View on GitHub (pinned to 265b3a3dec)
Solutions
- Pass an explicit larger maxBytes as the third ReadFile argument when bigger files are expected
- Read only the needed prefix (e.g. first 64 KiB of a config file) instead of raising the cap broadly
- Skip oversized files on error and continue the scan
Example fix
// before
const data = client.ReadFile('C$', '/inetpub/logs/log.txt', 0); // default 10 MiB cap
// after
const data = client.ReadFile('C$', '/inetpub/logs/log.txt', 50 * 1024 * 1024); Defensive patterns
Strategy: try-catch
Validate before calling
// pass an explicit cap matching your expectation before the call
const MAX = 20 * 1024 * 1024;
client.ReadFile('C$', '/big/log.txt', MAX); Try / catch
try { return client.ReadFile(share, path, cap); } catch (e) { if (String(e).includes('exceeds max read size')) { return null; /* skip oversized file */ } throw e; } Prevention
- Always pass an explicit maxBytes sized to intent
- Read only prefixes of large files
- Treat oversize errors as skip conditions in scan logic
When it happens
Trigger: Reading a file larger than 10 MiB with the default cap; passing an explicit maxBytes smaller than the target file; scanning hosts with large log/binary files at well-known paths.
Common situations: Templates reading log files, memory dumps, or installers that blow past the default; memory-protection limit kicking in when the author intended a full read.
Related errors
- tree listing exceeded max entries (%d)
- mount share %q: %w
- file path cannot be empty
- smb connect: %w
- dialers not initialized for %s
AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15).
Data as JSON: /api/errors/92ade4871ae48319.
Report an issue: GitHub.