使校验和“无效”的最佳方法

发布于 2024-11-15 03:08:17 字数 226 浏览 7 评论 0原文

假设我有一个 4KB 的缓冲区,其中在开始时包含一个校验和。该缓冲区包含引用其他缓冲区的元数据。注意缓冲区是内存映射文件。我注意到其中一个缓冲区无效(要么校验和不起作用,要么校验和很好,但它引用了无效的缓冲区)。现在,我想使引用另一个无效缓冲区的缓冲区无效。使缓冲区无效的数学最佳方法是什么?损坏校验和本身,使其可能与数据不匹配,或者损坏数据,使其可能与校验和不匹配。或者还有第三种更好的方法吗?就其价值而言,这是一个 CRC32 变体。

Let's say that I have a 4KB buffer that contains at the start a checksum. This buffer contains metadata that references other buffers. N.B. the buffers are memory mapped files. I notice that one of the buffers are invalid (either the checksum does not work out OR the checksum is fine but it references an invalid buffer). Now, I want to invalidate the buffer that references another invalid buffer. What is the mathematically best way to invalidate the buffer? Corrupt the checksum itself so that it might not match up with the data OR corrupt the data so it might not match up with the checksum. Or is there a third, better way altogether? For what its worth, this is a CRC32 variant.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2024-11-22 03:08:17

假设引用缓冲区的 CRC 有效,您只需从中减去 1,即可使缓冲区失效。根据您的描述,情况似乎是这样,因为您声明引用缓冲区的 CRC 可能是错误的。

如果引用的 CRC32无效,最安全的做法是计算 CRC然后减一。您首先需要知道正确的 CRC,因为随机选择的 CRC 虽然不太可能是正确的,但仍有大约四十亿分之一的正确机会。

更改 CRC 似乎是最安全的选择。如果不对 CRC32 算法进行数学分析,就无法保证对数据的特定更改不会生成相同 CRC 值(因为大量数据集可能会映射到相同的 CRC)。

然而,可以肯定的是,特定数据集将始终生成相同的 CRC,因此,通过将 CRC 更改为其他内容,您可以确保该块现在将无效。

Assuming the CRC of your referencing buffer is valid, you can just simply subtract one from it, that will invalidate your buffer just fine. From your description, this seems to be the case since you state that the referenced buffer is the one whose CRC may be wrong.

If the referencing CRC32 wasn't valid, the safest bet would be to calculate the CRC then subtract one. You need to know the correct CRC first because a random choice of CRC, whilst unlikely to be the correct one, still has a roughly one-in-four-billion chance of being right.

Changing the CRC seems like the safest option here. Short of doing a mathematical analysis of the CRC32 algorithm, there's no way to guarantee that a specific change to the data won't generate the same CRC value (since a large number of data sets may map to the same CRC).

However, it's a certainty that a specific data set will always generate the same CRC so, by changing the CRC to something else, you can be sure that the block will now be invalid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文