summaryrefslogtreecommitdiff
path: root/lib/tar
diff options
context:
space:
mode:
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;