Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
15d323541c
commit
1f31d7afae
@@ -198,15 +198,22 @@ func readEPUBCover(filePath string) ([]byte, string, error) {
|
|||||||
if path.Clean(f.Name) != coverPath {
|
if path.Clean(f.Name) != coverPath {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
const maxCoverBytes = 10 << 20 // 10 MiB
|
||||||
|
if f.UncompressedSize64 > uint64(maxCoverBytes) {
|
||||||
|
return nil, "", fmt.Errorf("cover image too large")
|
||||||
|
}
|
||||||
rc, err := f.Open()
|
rc, err := f.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
defer rc.Close()
|
defer rc.Close()
|
||||||
data, err := io.ReadAll(rc)
|
data, err := io.ReadAll(io.LimitReader(rc, int64(maxCoverBytes)+1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
|
if len(data) > maxCoverBytes {
|
||||||
|
return nil, "", fmt.Errorf("cover image too large")
|
||||||
|
}
|
||||||
return data, detectContentType(data, f.Name), nil
|
return data, detectContentType(data, f.Name), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user