summaryrefslogtreecommitdiff
path: root/lib/tar
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-11-18 00:57:01 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-11-18 00:58:13 +0100
commit844fdd42f03a633f1dbce5d90b2ecf44698cf8b0 (patch)
tree1255d42327bb297b12dfd4e7adfd81e3fbea6762 /lib/tar
parentda6eadc840716eb29b0175f39b2790bba166db4a (diff)
Add a single, central base64 decoder
Similar to the hex blob decoder, we need this once for tar and once for the filemap xattr parser. Simply add a single, central implementation to libutil, with a simple unit test, and then use it in both libtar and gensquashfs. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/tar')
-rw-r--r--lib/tar/pax_header.c62
1 files changed, 9 insertions, 53 deletions
diff --git a/lib/tar/pax_header.c b/lib/tar/pax_header.c
index cc2f2b0..b61aab6 100644
--- a/lib/tar/pax_header.c
+++ b/lib/tar/pax_header.c
@@ -11,56 +11,6 @@
#include <string.h>
#include <stdlib.h>
-static sqfs_u8 base64_convert(char in)
-{
- if (isupper(in))
- return in - 'A';
- if (islower(in))
- return in - 'a' + 26;
- if (isdigit(in))
- return in - '0' + 52;
- if (in == '+')
- return 62;
- if (in == '/' || in == '-')
- return 63;
- return 0;
-}
-
-static size_t base64_decode(sqfs_u8 *out, const char *in, size_t len)
-{
- sqfs_u8 *start = out;
-
- while (len > 0) {
- unsigned int diff = 0, value = 0;
-
- while (diff < 4 && len > 0) {
- if (*in == '=' || *in == '_' || *in == '\0') {
- len = 0;
- } else {
- value = (value << 6) | base64_convert(*(in++));
- --len;
- ++diff;
- }
- }
-
- if (diff < 2)
- break;
-
- value <<= 6 * (4 - diff);
-
- switch (diff) {
- case 4: out[2] = value & 0xff; /* fall-through */
- case 3: out[1] = (value >> 8) & 0xff; /* fall-through */
- default: out[0] = (value >> 16) & 0xff;
- }
-
- out += (diff * 3) / 4;
- }
-
- *out = '\0';
- return out - start;
-}
-
static int pax_read_decimal(const char *str, sqfs_u64 *out)
{
sqfs_u64 result = 0;
@@ -201,10 +151,16 @@ static int pax_xattr_schily(tar_header_decoded_t *out,
static int pax_xattr_libarchive(tar_header_decoded_t *out,
tar_xattr_t *xattr)
{
+ int ret;
+
+ ret = base64_decode((const char *)xattr->value, xattr->value_len,
+ xattr->value, &xattr->value_len);
+ if (ret)
+ return -1;
+
urldecode(xattr->key);
- xattr->value_len = base64_decode(xattr->value,
- (const char *)xattr->value,
- xattr->value_len);
+
+ xattr->value[xattr->value_len] = '\0';
xattr->next = out->xattr;
out->xattr = xattr;
return 0;