Handle PNG EXIF and distinguish transient encoder crashes from invalid images
This commit is contained in:
@@ -306,7 +306,8 @@ func (p *Pipeline) process(parent context.Context, j Job) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
var errInvalidImage = errors.New("invalid_image")
|
||||
var ErrInvalidImage = errors.New("invalid_image")
|
||||
var errInvalidImage = ErrInvalidImage
|
||||
|
||||
func resultPrefix(j Job) string {
|
||||
return "originals/" + j.AttachmentID + "/v" + strconv.Itoa(j.Version) + "/"
|
||||
@@ -346,10 +347,7 @@ func (p *Pipeline) perform(ctx context.Context, j Job, key, sha, contentType str
|
||||
// an orphan encoder outliving the transform deadline (Linux container only).
|
||||
configureChild(cmd)
|
||||
if e = cmd.Run(); e != nil {
|
||||
if transformCtx.Err() != nil {
|
||||
return nil, transformCtx.Err()
|
||||
}
|
||||
return nil, errInvalidImage
|
||||
return nil, classifyTransformFailure(transformCtx.Err(), e)
|
||||
}
|
||||
raw, e := os.ReadFile(filepath.Join(dir, "variants.json"))
|
||||
if e != nil {
|
||||
@@ -397,3 +395,15 @@ func faultPoint(point string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A killed/crashed encoder is not evidence of an invalid source image.
|
||||
func classifyTransformFailure(deadline, errorResult error) error {
|
||||
if deadline != nil {
|
||||
return deadline
|
||||
}
|
||||
var exited *exec.ExitError
|
||||
if errors.As(errorResult, &exited) && exited.ExitCode() == 65 {
|
||||
return ErrInvalidImage
|
||||
}
|
||||
return fmt.Errorf("transform temporarily unavailable")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user