Update pickle.c

This commit is contained in:
blueloveTH 2025-04-05 02:59:07 +08:00
parent f99c02abb8
commit 4bf59223b3

View File

@ -445,6 +445,11 @@ bool py_pickle_loads_body(const unsigned char* p, int memo_length, c11_smallmap_
bool py_pickle_loads(const unsigned char* data, int size) { bool py_pickle_loads(const unsigned char* data, int size) {
const unsigned char* p = data; const unsigned char* p = data;
// \xf0\x9f\xa5\x95
if(size < 4 || p[0] != 240 || p[1] != 159 || p[2] != 165 || p[3] != 149)
return ValueError("invalid pickle data");
p += 4;
c11_smallmap_n2i type_mapping; c11_smallmap_n2i type_mapping;
c11_smallmap_n2i__ctor(&type_mapping); c11_smallmap_n2i__ctor(&type_mapping);
@ -703,6 +708,7 @@ bool py_pickle_loads_body(const unsigned char* p, int memo_length, c11_smallmap_
static bool PickleObject__py_submit(PickleObject* self, py_OutRef out) { static bool PickleObject__py_submit(PickleObject* self, py_OutRef out) {
c11_sbuf cleartext; c11_sbuf cleartext;
c11_sbuf__ctor(&cleartext); c11_sbuf__ctor(&cleartext);
c11_sbuf__write_cstr(&cleartext, "\xf0\x9f\xa5\x95");
// line 1: type mapping // line 1: type mapping
for(py_Type type = 0; type < self->used_types_length; type++) { for(py_Type type = 0; type < self->used_types_length; type++) {
if(self->used_types[type]) { if(self->used_types[type]) {