顺便说一句:这听起来像是一个巨魔,但老实说,我建议您考虑完全删除此cbor解析器:它没有正确实现标准,代码质量太差了,最重要的是,它充满了错误并且似乎没有积极从事此工作的维护人员。
@nmeum ,您能否详细说明一下代码质量问题和RFC符合性问题?
关于RFC合规性:解析器无法正确解析大多数cbor testvectors 。 关于代码质量:我们只是通过模糊处理代码来解决这些问题,从而发现了多个问题,但看起来似乎还不够完善。
这是修复cbor解析器中的挂起(或至少其中一些挂起)的补丁:
diff --git a/cbor-afl/cbor.c b/cbor-afl/cbor.c
index fa1aa27..c97457e 100644
--- a/cbor-afl/cbor.c
+++ b/cbor-afl/cbor.c
@@ -989,12 +989,17 @@ static size_t cbor_stream_decode_at(cbor_stream_t *stream, size_t offset, int in
while (is_indefinite ? !cbor_at_break(stream, offset) : i < map_length) {
size_t key_read_bytes, value_read_bytes;
+
offset += key_read_bytes = cbor_stream_decode_at(stream, offset, indent + 1); /* key */
- offset += value_read_bytes = cbor_stream_decode_at(stream, offset, indent + 2); /* value */
+ if (key_read_bytes == 0) {
+ DEBUG("Failed to read key at position %d\n", i);
+ return 0;
+ }
- if (key_read_bytes == 0 || value_read_bytes == 0) {
- DEBUG("Failed to read key-value pair at position %d\n", i);
- break;
+ offset += value_read_bytes = cbor_stream_decode_at(stream, offset, indent + 2); /* value */
+ if (value_read_bytes == 0) {
+ DEBUG("Failed to read value at position %d\n", i);
+ return 0;
}
read_bytes += key_read_bytes + value_read_bytes;
问题似乎是解析器在解析映射中的键值后没有检查错误。 因此,即使未找到键,它仍会调用cbor_stream_decode_at
来查找不存在的键的值。
不确定补丁是否是最佳的,但至少它不再挂起了……
我已经收集了#7800中所有与cbor
相关的问题。 让我们在那里讨论如何继续该模块。
最有用的评论
顺便说一句:这听起来像是一个巨魔,但老实说,我建议您考虑完全删除此cbor解析器:它没有正确实现标准,代码质量太差了,最重要的是,它充满了错误并且似乎没有积极从事此工作的维护人员。