🐛 Fix bug crash caused by hash small files
This commit is contained in:
parent
cbe034a049
commit
a9156992f4
@ -4,7 +4,7 @@
|
|||||||
<option name="autoReloadType" value="ALL" />
|
<option name="autoReloadType" value="ALL" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":zap: Use exif whitelist to prevent produce garbage data">
|
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Trying to prevent exiftool causing analyze failed">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/analyzer.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/analyzer.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/internal/services/analyzer.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/analyzer.go" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
@ -117,7 +117,6 @@
|
|||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value=":sparkles: Pool clean by lifecycle config" />
|
|
||||||
<MESSAGE value=":recycle: Split mark and delete file" />
|
<MESSAGE value=":recycle: Split mark and delete file" />
|
||||||
<MESSAGE value=":bug: Fix migration issue on pools" />
|
<MESSAGE value=":bug: Fix migration issue on pools" />
|
||||||
<MESSAGE value=":bug: Fix schedule deletion will delete referenced file" />
|
<MESSAGE value=":bug: Fix schedule deletion will delete referenced file" />
|
||||||
@ -142,7 +141,8 @@
|
|||||||
<MESSAGE value=":lock: Fix Attachment will contains GPS information" />
|
<MESSAGE value=":lock: Fix Attachment will contains GPS information" />
|
||||||
<MESSAGE value=":sparkles: Save EXIF into file metadata" />
|
<MESSAGE value=":sparkles: Save EXIF into file metadata" />
|
||||||
<MESSAGE value=":zap: Use exif whitelist to prevent produce garbage data" />
|
<MESSAGE value=":zap: Use exif whitelist to prevent produce garbage data" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value=":zap: Use exif whitelist to prevent produce garbage data" />
|
<MESSAGE value=":bug: Trying to prevent exiftool causing analyze failed" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value=":bug: Trying to prevent exiftool causing analyze failed" />
|
||||||
</component>
|
</component>
|
||||||
<component name="VgoProject">
|
<component name="VgoProject">
|
||||||
<settings-migrated>true</settings-migrated>
|
<settings-migrated>true</settings-migrated>
|
||||||
|
@ -277,6 +277,14 @@ func HashAttachment(file models.Attachment) (hash string, err error) {
|
|||||||
|
|
||||||
hasher := sha256.New()
|
hasher := sha256.New()
|
||||||
|
|
||||||
|
if chunkSize*3 <= fileInfo.Size() {
|
||||||
|
// If the total size is smaller than three chunks, then hash the whole file
|
||||||
|
buf := make([]byte, fileInfo.Size())
|
||||||
|
if _, err := inFile.Read(buf); err != nil && err != io.EOF {
|
||||||
|
return "", fmt.Errorf("error reading whole file: %v", err)
|
||||||
|
}
|
||||||
|
hasher.Write(buf)
|
||||||
|
} else {
|
||||||
// Hash the first 32KB
|
// Hash the first 32KB
|
||||||
buf := make([]byte, chunkSize)
|
buf := make([]byte, chunkSize)
|
||||||
if _, err := inFile.Read(buf); err != nil && err != io.EOF {
|
if _, err := inFile.Read(buf); err != nil && err != io.EOF {
|
||||||
@ -303,6 +311,7 @@ func HashAttachment(file models.Attachment) (hash string, err error) {
|
|||||||
return "", fmt.Errorf("error reading end: %v", err)
|
return "", fmt.Errorf("error reading end: %v", err)
|
||||||
}
|
}
|
||||||
hasher.Write(buf)
|
hasher.Write(buf)
|
||||||
|
}
|
||||||
|
|
||||||
// Hash with the file metadata
|
// Hash with the file metadata
|
||||||
hasher.Write([]byte(fmt.Sprintf("%d", file.Size)))
|
hasher.Write([]byte(fmt.Sprintf("%d", file.Size)))
|
||||||
|
Loading…
Reference in New Issue
Block a user