Skip to content

Fixed base64 decoding in mruby-pack#6243

Merged
matz merged 1 commit into
mruby:masterfrom
dearblue:base64
Apr 20, 2024
Merged

Fixed base64 decoding in mruby-pack#6243
matz merged 1 commit into
mruby:masterfrom
dearblue:base64

Conversation

@dearblue

Copy link
Copy Markdown
Contributor

Previously \x80 was incorrectly mapped to 0.

"\x80\x80\x80\x80".unpack("m*")
# before => "\x00\x00\x00"
# after  => ""

The reason is that the C string terminator is placed in base64_dec_tab[128] and the array length is obtained by sizeof. Therefore, the length of base64_dec_tab[] is strictly specified and replaced with element-by-element initialization.

Also, similar changes are made to base64chars[].

Previously `\x80` was incorrectly mapped to `0`.

```ruby
"\x80\x80\x80\x80".unpack("m*")
# before => "\x00\x00\x00"
# after  => ""
```

The reason is that the C string terminator is placed in `base64_dec_tab[128]` and the array length is obtained by `sizeof`.
Therefore, the length of `base64_dec_tab[]` is strictly specified and replaced with element-by-element initialization.

Also, similar changes are made to `base64chars[]`.
@dearblue
dearblue requested a review from matz as a code owner April 20, 2024 01:01
@matz
matz merged commit ad476c3 into mruby:master Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants