-
-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Bad request when trying to use very small avatars/banners #2263
Comments
how big in bytes are these files? |
It's probably giving bad request because the image is too small for us to derive the type from the magic bytes. Not 100% sure though, logs would be helpful. |
The only output I see via
I used a one-pixel GIF this time, which is 35b. |
Could you check the response via the network tab (or equivalent for your browser) when doing an upload via the settings panel? That should give more information, i hope. |
The only "information" I could get from the failed request is this:
|
Alright, annoying that it gives no errors, but that's OK. I'm fairly sure it's here where it's going wrong: gotosocial/internal/media/processingmedia.go Lines 159 to 162 in 39e22a9
We use those first 261 bytes as the 'magic' bytes for working out what format a file is. So a 35b 1-pixel gif isn't gonna work there. An 8x8 pixel gif or something, on the other hand, would probably work. |
The problem with this use case of solid colors & efficient image codecs is that no matter what the resolution is, you won't exceed the necessary bytes until you introduce noise or just simply upload an actual complex image. Reading the README of h2non/filetype: the buffer does not need to be filled, so maybe some kind of IO method is not being used correctly. |
Yes probably something like that. We'll take a better look at it when time allows. |
it's there a way to make this read graceful? |
I think gotosocial/internal/media/processingmedia.go Lines 159 to 167 in 39e22a9
How about using func Example() {
// 1x1 px transparent GIF image
imgBase64 := "R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
imgBin, err := base64.StdEncoding.DecodeString(imgBase64)
PanicOnErr(err)
hdrBuf := make([]byte, 261)
// rc := bytes.NewReader(imgBin)
// _, err = io.ReadFull(rc, hdrBuf)
// PanicOnErr(err)
_ = copy(hdrBuf, imgBin)
info, err := filetype.Match(hdrBuf)
PanicOnErr(err)
fmt.Printf("%s\n", info.MIME.Value)
// Output:
// image/gif
}
func PanicOnErr(err error) {
if err != nil {
log.Panic(err)
}
} If it sounds ok I shall PR. |
PR would be great! :) |
Done 👍 Hope it helps! |
Describe the bug with a clear and concise description of what the bug is.
When trying to upload an image that's too small (1x1 image for example) as the avatar or banner the backend just returns Bad Request.
What's your GoToSocial Version?
v0.11.1 git-c7a46e0
GoToSocial Arch
arm64 binary
The text was updated successfully, but these errors were encountered: