Skip to content

Commit

Permalink
Fix base64 decoding for length= argument and non-padding decoding
Browse files Browse the repository at this point in the history
When decoding only a substring, we naturally see no padding, so we must
not base tail processing on the number of pad characters seen, but
rather on the number of characters missing until the end of the current
block of four.

Fixes #3378
  • Loading branch information
nigoroll committed Aug 6, 2020
1 parent a390e08 commit fb044cb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/varnishtest/tests/m00042.vtc
Expand Up @@ -263,7 +263,7 @@ client c1 {
expect resp.http.hexmix2hexlc == resp.http.hexmix2hex
expect resp.http.hexparam == "0123456789"
expect resp.http.b642b64 == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij"
expect resp.http.b64url2b64url == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefeQ=="
expect resp.http.b64url2b64url == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgg=="
expect resp.http.b64urlnopad2b64urlnopad == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgg"
} -run

Expand Down
2 changes: 1 addition & 1 deletion lib/libvmod_blob/base64.c
Expand Up @@ -309,7 +309,7 @@ base64_decode(const enum encoding dec, blob_dest_t buf,
}
}
if (n) {
if (!alpha->padding)
if (n - term != 0)
u <<= (6 * (4 - n));
if (decode(&dest, buf, buflen, u, n-term) < 0)
return (-1);
Expand Down

0 comments on commit fb044cb

Please sign in to comment.