Skip to content

[BUG] 特定场景下计算得到的hash值不正确 #1583

@j2rong4cn

Description

@j2rong4cn

有部分网盘会获取preHash,如115和阿里,但获取preHash后,再调用CacheFullAndHash返回的hash值是错的,能不能修复下,下面这个测试能重现:

func TestFileStream_With_PreHash(t *testing.T) {
	conf.MaxBufferLimit = 16 * 1024 * 1024
	type args struct {
		httpRange http_range.Range
	}
	buf := []byte("github.com/OpenListTeam/OpenList")
	f := &FileStream{
		Obj: &model.Object{
			Size: int64(len(buf)),
		},
		Reader: io.NopCloser(bytes.NewReader(buf)),
	}

	const hashSize int64 = 20
	reader, _ := f.RangeRead(http_range.Range{Start: 0, Length: hashSize})
	preHash, _ := utils.HashReader(utils.SHA1, reader)
	if preHash == "" {
		t.Error("preHash is empty")
	}
	tmpF, fullHash, _ := CacheFullAndHash(f, nil, utils.SHA1)
	fmt.Println(fullHash)
	fileFullHash, _ := utils.HashFile(utils.SHA1, tmpF)
	fmt.Println(fileFullHash)
	if fullHash != fileFullHash {
		t.Errorf("fullHash and fileFullHash should match: fullHash=%s fileFullHash=%s", fullHash, fileFullHash)
	}
}

去掉前面的preHash调用,才能获取到正确的hash值

Originally posted by @bitxeno in #1001 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions