mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-13 06:33:44 +01:00
Use 25% less RAM for base64-encoded directory objects
We were allocating N bytes to decode an N-byte base64 encoding, when 3N/4 would have been enough.
This commit is contained in:
parent
3c35c0d441
commit
6dc90d290d
@ -393,8 +393,9 @@ get_next_token(memarea_t *area,
|
|||||||
RET_ERR("Couldn't parse private key.");
|
RET_ERR("Couldn't parse private key.");
|
||||||
} else { /* If it's something else, try to base64-decode it */
|
} else { /* If it's something else, try to base64-decode it */
|
||||||
int r;
|
int r;
|
||||||
tok->object_body = ALLOC(next-*s); /* really, this is too much RAM. */
|
size_t maxsize = base64_decode_maxsize(next-*s);
|
||||||
r = base64_decode(tok->object_body, next-*s, *s, next-*s);
|
tok->object_body = ALLOC(maxsize);
|
||||||
|
r = base64_decode(tok->object_body, maxsize, *s, next-*s);
|
||||||
if (r<0)
|
if (r<0)
|
||||||
RET_ERR("Malformed object: bad base64-encoded data");
|
RET_ERR("Malformed object: bad base64-encoded data");
|
||||||
tok->object_size = r;
|
tok->object_size = r;
|
||||||
|
Loading…
Reference in New Issue
Block a user