AlistGo/alist · error

wrong sha1 hash

Error message

wrong sha1 hash

What it means

When the optional sha1 field in metadata is non-empty, it must be exactly 40 hex-decodable characters (a canonical SHA1 digest). Failing hex.DecodeString or length != 40 returns 'wrong sha1 hash'. Like the md5 check, it prevents garbage digests from entering integrity verification.

Source

Thrown at drivers/chunker/util.go:248

		return nil, errors.New("missing required field")
	}
	if *meta.Version < 1 {
		return nil, errors.New("wrong version")
	}
	if *meta.Size < 0 {
		return nil, errors.New("negative file size")
	}
	if *meta.ChunkNum < 1 || *meta.ChunkNum > maxSafeChunkNumber {
		return nil, errors.New("wrong number of chunks")
	}
	if meta.MD5 != "" {
		if _, err := hex.DecodeString(meta.MD5); err != nil || len(meta.MD5) != 32 {
			return nil, errors.New("wrong md5 hash")
		}
	}
	if meta.SHA1 != "" {
		if _, err := hex.DecodeString(meta.SHA1); err != nil || len(meta.SHA1) != 40 {
			return nil, errors.New("wrong sha1 hash")
		}
	}
	if *meta.Version > chunkerMetadataVerion {
		return nil, errors.New("unknown metadata version")
	}
	return &chunkMetadata{
		Version: *meta.Version,
		Size:    *meta.Size,
		NChunks: *meta.ChunkNum,
		MD5:     meta.MD5,
		SHA1:    meta.SHA1,
		XactID:  meta.XactID,
	}, nil
}

func joinRemotePathWithBase(baseMountPath, logicalPath string) string {
	logicalPath = utils.FixAndCleanPath(logicalPath)
	if utils.PathEqual(logicalPath, "/") {

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Correct the field to a 40-char lowercase hex SHA1, or blank it out (empty skips validation)
  2. Regenerate metadata by re-uploading the file through the driver
  3. Align your external tooling's digest field names with the metadata schema (md5->32 hex, sha1->40 hex)

Example fix

// before (metadata file content)
{"ver":1,"size":1024,"nchunks":2,"sha1":"<64-char sha256>"}
// after
{"ver":1,"size":1024,"nchunks":2,"sha1":"<40-char sha1 hex>"}
Defensive patterns

Strategy: type-guard

Validate before calling

if meta.SHA1 != "" {
    if _, err := hex.DecodeString(meta.SHA1); err != nil || len(meta.SHA1) != 40 {
        return fmt.Errorf("sha1 must be 40 hex chars or empty")
    }
}

Type guard

func isValidSHA1Field(s string) bool {
    if s == "" { return true }
    _, err := hex.DecodeString(s)
    return err == nil && len(s) == 40
}

Prevention

When it happens

Trigger: Metadata with "sha1":"<64-char sha256 hex>", a 32-char MD5 in the sha1 field, non-hex characters, or a truncated digest. Surfaced whenever the chunker parses that file's metadata.

Common situations: Scripts writing SHA256 into the sha1 slot; algorithm renaming in a pipeline; uppercase or prefixed digests ('sha1:abc...').

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/0df4475e6b5aa74f. Report an issue: GitHub.