mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 16:37:27 +00:00
base64 decode present dnd source data
This commit is contained in:
parent
0619c7e435
commit
281cff0b60
3 changed files with 23 additions and 3 deletions
|
|
@ -10,9 +10,21 @@
|
|||
#include <stdbool.h>
|
||||
#include "../3rdparty/base64/include/libbase64.h"
|
||||
|
||||
typedef struct base64_state base64_state;
|
||||
|
||||
static inline size_t required_buffer_size_for_base64_decode(size_t src_sz) { return (src_sz / 4 * 3 + 2); }
|
||||
static inline size_t required_buffer_size_for_base64_encode(size_t src_sz) { return ((src_sz + 2) / 3 * 4); }
|
||||
|
||||
static inline void
|
||||
base64_init_stream_decoder(base64_state *state) {
|
||||
base64_stream_decode_init(state, 0);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
base64_decode_stream(base64_state *state, const uint8_t *src, size_t src_sz, uint8_t *dest, size_t *dest_sz) {
|
||||
if (*dest_sz < required_buffer_size_for_base64_decode(src_sz)) return false;
|
||||
return base64_stream_decode(state, (const char*)src, src_sz, (char*)dest, dest_sz) == 1;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
base64_decode8(const uint8_t *src, size_t src_sz, uint8_t *dest, size_t *dest_sz) {
|
||||
|
|
|
|||
|
|
@ -912,14 +912,19 @@ drag_add_pre_sent_data(Window *w, unsigned idx, const uint8_t *payload, size_t s
|
|||
if (sz + ds.pre_sent_total_sz > 64 * 1024 * 1024) abrt(EFBIG);
|
||||
ds.pre_sent_total_sz += sz;
|
||||
DragSourceItem *item = ds.items + idx;
|
||||
if (!item->data_decode_initialized) {
|
||||
item->data_decode_initialized = true;
|
||||
base64_init_stream_decoder(&item->base64_state);
|
||||
}
|
||||
if (item->data_capacity < sz + item->data_size) {
|
||||
size_t newcap = MAX(item->data_size * 2, sz + item->data_size);
|
||||
item->optional_data = realloc(item->optional_data, newcap);
|
||||
if (!item->optional_data) abrt(ENOMEM);
|
||||
item->data_capacity = newcap;
|
||||
}
|
||||
memcpy(item->optional_data + item->data_size, payload, sz);
|
||||
item->data_size += sz;
|
||||
size_t outlen = item->data_capacity - item->data_size;
|
||||
if (!base64_decode_stream(&item->base64_state, payload, sz, item->optional_data + item->data_size, &outlen)) abrt(EINVAL);
|
||||
item->data_size += outlen;
|
||||
}
|
||||
|
||||
#undef abrt
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "screen.h"
|
||||
#include "monotonic.h"
|
||||
#include "window_logo.h"
|
||||
#include "base64.h"
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#include <hb.h>
|
||||
|
|
@ -235,8 +236,10 @@ typedef struct DirHandle {
|
|||
|
||||
typedef struct DragSourceItem {
|
||||
const char *mime_type;
|
||||
char *optional_data;
|
||||
uint8_t *optional_data;
|
||||
size_t data_size, data_capacity;
|
||||
base64_state base64_state;
|
||||
bool data_decode_initialized;
|
||||
} DragSourceItem;
|
||||
|
||||
typedef struct Window {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue