mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 09:01:35 +01:00
Add more internal errors to wuffs_aux Cbor, Json
This commit is contained in:
1 parent
a83b5cabaf
commit
341dd50800
4 files changed
+140
-56
No files matched your search
@@ -57,7 +57,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
// Prepare the low-level CBOR decoder.
|
||||
wuffs_cbor__decoder::unique_ptr dec = wuffs_cbor__decoder::alloc();
|
||||
if (!dec) {
|
||||
ret_error_message = "wuffs_aux::CborDecoder: out of memory";
|
||||
ret_error_message = "wuffs_aux::DecodeCbor: out of memory";
|
||||
goto done;
|
||||
}
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
@@ -72,7 +72,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
|
||||
|
||||
// Prepare other state.
|
||||
uint32_t depth = 0;
|
||||
int32_t depth = 0;
|
||||
std::string str;
|
||||
int64_t extension_category = 0;
|
||||
uint64_t extension_detail = 0;
|
||||
@@ -99,17 +99,17 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
} else if (cursor_index != io_buf->meta.ri) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad cursor_index";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad cursor_index";
|
||||
goto done;
|
||||
} else if (io_buf->meta.closed) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: io_buf is closed";
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is closed";
|
||||
goto done;
|
||||
}
|
||||
io_buf->compact();
|
||||
if (io_buf->meta.wi >= io_buf->data.len) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: io_buf is full";
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is full";
|
||||
goto done;
|
||||
}
|
||||
cursor_index = io_buf->meta.ri;
|
||||
@@ -121,11 +121,19 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
|
||||
if (WUFFS_CBOR__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad WORKBUF_LEN";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad WORKBUF_LEN";
|
||||
goto done;
|
||||
}
|
||||
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8();
|
||||
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf);
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) ||
|
||||
(tok_buf.meta.wi > tok_buf.data.len) ||
|
||||
(io_buf->meta.ri > io_buf->meta.wi) ||
|
||||
(io_buf->meta.wi > io_buf->data.len)) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad buffer indexes";
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++];
|
||||
@@ -133,7 +141,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
if ((io_buf->meta.ri < cursor_index) ||
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad token indexes";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad token indexes";
|
||||
goto done;
|
||||
}
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index;
|
||||
@@ -169,7 +177,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
}
|
||||
}
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad extended token";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad extended token";
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -184,10 +192,20 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_CBOR__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));
|
||||
depth--;
|
||||
if (depth < 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
goto parsed_a_value;
|
||||
}
|
||||
|
||||
@@ -324,7 +342,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
|
||||
fail:
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: unexpected token";
|
||||
"wuffs_aux::DecodeCbor: internal error: unexpected token";
|
||||
goto done;
|
||||
|
||||
parsed_a_value:
|
||||
|
||||
Reference in new issue
Block a user