From ead2a7c0183fd786386c2c52a9e130d71366ed0a Mon Sep 17 00:00:00 2001 From: Arya Khochare <91268931+Aryakoste@users.noreply.github.com> Date: Fri, 8 Nov 2024 20:09:03 +0530 Subject: [PATCH] Fixed errcheck issues in server/channels/app/imaging/decode.go (#28937) --- server/.golangci.yml | 1 - server/channels/app/imaging/decode.go | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/.golangci.yml b/server/.golangci.yml index 5ab81eee5c7..ff0ee3fd7c7 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -96,7 +96,6 @@ issues: channels/app/file_info.go|\ channels/app/file_test.go|\ channels/app/helper_test.go|\ - channels/app/imaging/decode.go|\ channels/app/import_functions.go|\ channels/app/import_functions_test.go|\ channels/app/imports/import_validators.go|\ diff --git a/server/channels/app/imaging/decode.go b/server/channels/app/imaging/decode.go index 215c4caf27b..756ee1f8eef 100644 --- a/server/channels/app/imaging/decode.go +++ b/server/channels/app/imaging/decode.go @@ -112,12 +112,16 @@ func (d *Decoder) DecodeConfig(rd io.Reader) (image.Config, string, error) { } // GetDimensions returns the dimensions for the given encoded image data. -func GetDimensions(imageData io.Reader) (int, int, error) { +func GetDimensions(imageData io.Reader) (width int, height int, err error) { cfg, _, err := image.DecodeConfig(imageData) + width, height = cfg.Width, cfg.Height if seeker, ok := imageData.(io.Seeker); ok { - defer seeker.Seek(0, 0) + _, err2 := seeker.Seek(0, 0) + if err == nil && err2 != nil { + err = fmt.Errorf("failed to seek back to the beginning of the image data: %w", err2) + } } - return cfg.Width, cfg.Height, err + return } // This is only needed to try and simplify GC work.