Blueforcer / awtrix3

Custom firmware for the Ulanzi Smart Pixel clock or self made awtrix. Getting started is easy as 1-2-3
https://blueforcer.github.io/awtrix3/
Other
1.26k stars 109 forks source link

[BUG] Base64 icons not working without "=" padding #427

Closed magcode closed 9 months ago

magcode commented 9 months ago

Bug report

Describe the bug

Some base64 encoded icons are not recognized.

Example is attached 1

base64 of this image is

/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAIAAgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD0TW9XstQtmMVzNcW8Esbzx22VZADwc8ZHQ4zRRRXApO1z0YaKyP/Z

Additional information

To Reproduce

Send above base64 as icon.

Expected behavior

All base64 encoded icons work.

Blueforcer commented 9 months ago

Currently I don't know how to detect a base64 string except of the trailing =.

Maybe according to a length

magcode commented 9 months ago

Regex maybe?

https://stackoverflow.com/a/8571649

magcode commented 9 months ago

Yeah, length would be much easier. Everything above 32 (?) chars can be safely treated as a base64.

fasterit commented 9 months ago

As I wrote on Discord: JPGs will always start with hex FF D8 FF which will lead to the base64 start of /9j/ (including the /'s). So if you use that to detect, you are safer. Also GIFs start with GIF8, so you can use R0lG at the start of base64 to detect these. (you can combine this with the length test, in case somebody wants to make a very strange icon file name :smiley:) /Greets DLange

Blueforcer commented 9 months ago

Checking the jpg header would require to encode the base64 string first. GIFs as base64 are still not possible. For now awtrix checks the stringlenght.

https://github.com/Blueforcer/awtrix-light/releases/tag/0.92