fix: 보안 강화 및 안정성 개선
- extractZip: io.LimitReader 적용으로 zip bomb 방어 (개별 파일 4GB 제한) - moveContents: cross-drive 복사 실패 시 부분 파일 제거 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
4
main.go
4
main.go
@@ -30,6 +30,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const maxDownloadSize = 2 << 30 // 2GB
|
const maxDownloadSize = 2 << 30 // 2GB
|
||||||
|
const maxExtractFileSize = 4 << 30 // 개별 파일 최대 4GB
|
||||||
|
|
||||||
var checkRedirect = func(req *http.Request, via []*http.Request) error {
|
var checkRedirect = func(req *http.Request, via []*http.Request) error {
|
||||||
if req.URL.Scheme != "https" && req.URL.Scheme != "http" {
|
if req.URL.Scheme != "https" && req.URL.Scheme != "http" {
|
||||||
@@ -559,7 +560,7 @@ func extractZip(zipPath, destDir string) error {
|
|||||||
rc.Close()
|
rc.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = io.Copy(out, rc)
|
_, err = io.Copy(out, io.LimitReader(rc, maxExtractFileSize))
|
||||||
out.Close()
|
out.Close()
|
||||||
rc.Close()
|
rc.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -589,6 +590,7 @@ func moveContents(srcDir, dstDir string) error {
|
|||||||
if err := os.Rename(src, dst); err != nil {
|
if err := os.Rename(src, dst); err != nil {
|
||||||
// 드라이브가 다를 경우 복사 후 삭제
|
// 드라이브가 다를 경우 복사 후 삭제
|
||||||
if err := copyFile(src, dst); err != nil {
|
if err := copyFile(src, dst); err != nil {
|
||||||
|
os.Remove(dst) // 실패한 부분 파일 제거
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user