mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-17 07:57:37 +08:00
fix: check os.ReadFile error before using file contents
http.DetectContentType was called with potentially nil/empty contents when ReadFile failed; the error was only checked afterward. Move the error check immediately after ReadFile so bad data is never used. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
8205794e7b
commit
9e7f2cf9d5
@ -102,6 +102,9 @@ func resolveLink(
|
||||
}
|
||||
|
||||
linkContents, err := os.ReadFile(filepath)
|
||||
if err != nil {
|
||||
return "", karma.Format(err, "read file: %s", filepath)
|
||||
}
|
||||
|
||||
contentType := http.DetectContentType(linkContents)
|
||||
// Check if the MIME type starts with "text/"
|
||||
@ -110,10 +113,6 @@ func resolveLink(
|
||||
return "", nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", karma.Format(err, "read file: %s", filepath)
|
||||
}
|
||||
|
||||
linkContents = bytes.ReplaceAll(
|
||||
linkContents,
|
||||
[]byte("\r\n"),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user