fix: validate --max-hamt-fanout CLI flag per UnixFS spec#11230
Open
fix: validate --max-hamt-fanout CLI flag per UnixFS spec#11230
Conversation
the CLI flag bypassed the config validation in ValidateImportConfig, allowing spec-noncompliant values (e.g. 3 or 999999) to be silently accepted. validation now happens in the options layer, covering both CLI and programmatic API usage.
guillaumemichel
approved these changes
Mar 11, 2026
Contributor
guillaumemichel
left a comment
There was a problem hiding this comment.
nit: the phrasing multiple of 8 AND power of 2 sounds weird. (all powers of 2 beyond 8 are multiples of 8).
IMO "power of 2, between 8 and 1024" is clearer for users.
| cmds.IntOption(maxFileLinksOptionName, "Limit the maximum number of links in UnixFS file nodes to this value. WARNING: experimental. Default: Import.UnixFSFileMaxLinks"), | ||
| cmds.IntOption(maxDirectoryLinksOptionName, "Limit the maximum number of links in UnixFS basic directory nodes to this value. WARNING: experimental, Import.UnixFSHAMTDirectorySizeThreshold is safer. Default: Import.UnixFSDirectoryMaxLinks"), | ||
| cmds.IntOption(maxHAMTFanoutOptionName, "Limit the maximum number of links of a UnixFS HAMT directory node to this (power of 2, multiple of 8). WARNING: experimental, Import.UnixFSHAMTDirectorySizeThreshold is safer. Default: Import.UnixFSHAMTDirectoryMaxFanout"), | ||
| cmds.IntOption(maxHAMTFanoutOptionName, "Limit the maximum number of links of a UnixFS HAMT directory node to this (power of 2, multiple of 8, at most 1024). WARNING: experimental, Import.UnixFSHAMTDirectorySizeThreshold is safer. Default: Import.UnixFSHAMTDirectoryMaxFanout"), |
Contributor
There was a problem hiding this comment.
Suggested change
| cmds.IntOption(maxHAMTFanoutOptionName, "Limit the maximum number of links of a UnixFS HAMT directory node to this (power of 2, multiple of 8, at most 1024). WARNING: experimental, Import.UnixFSHAMTDirectorySizeThreshold is safer. Default: Import.UnixFSHAMTDirectoryMaxFanout"), | |
| cmds.IntOption(maxHAMTFanoutOptionName, "Limit the maximum number of links of a UnixFS HAMT directory node to this (power of 2, between 8 and 1024). WARNING: experimental, Import.UnixFSHAMTDirectorySizeThreshold is safer. Default: Import.UnixFSHAMTDirectoryMaxFanout"), |
Comment on lines
+236
to
+237
| // Per the UnixFS spec, the value must be a power of 2, a multiple of 8 | ||
| // (for byte-aligned bitfields), and at most 1024. |
Contributor
There was a problem hiding this comment.
Suggested change
| // Per the UnixFS spec, the value must be a power of 2, a multiple of 8 | |
| // (for byte-aligned bitfields), and at most 1024. | |
| // Per the UnixFS spec, the value must be a power of 2, minimum 8 | |
| // (for byte-aligned bitfields), and maximum 1024. |
| func (unixfsOpts) MaxHAMTFanout(n int) UnixfsAddOption { | ||
| return func(settings *UnixfsAddSettings) error { | ||
| if n < 8 || n&(n-1) != 0 || n > 1024 { | ||
| return fmt.Errorf("HAMT fanout must be a power of 2, a multiple of 8, and at most 1024 (got %d)", n) |
Contributor
There was a problem hiding this comment.
Suggested change
| return fmt.Errorf("HAMT fanout must be a power of 2, a multiple of 8, and at most 1024 (got %d)", n) | |
| return fmt.Errorf("HAMT fanout must be a power of 2, between 8 and 1024 (got %d)", n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
the CLI flag bypassed the config validation in ValidateImportConfig, allowing spec-noncompliant values (e.g. 3 or 999999) to be silently accepted. validation now happens in the options layer, covering both CLI and programmatic API usage.