Commit 512329c2 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Fix checksumming of large objects.

The current code has a potential problem when checksums are computed
for objects larger than 32bit allows for.
parent 6b3fdb21
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <inttypes.h>
#include <sys/types.h>
#include <stdlib.h>
#include "cdi_cksum.h"
......
#include <inttypes.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <inttypes.h>
#include <stdlib.h>
#include <sys/types.h>
#include "cksum.h"
static const uint32_t crctab[] = {
0x00000000,
0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
......@@ -71,18 +73,13 @@ memcrc(const unsigned char *b, size_t n)
*/
register uint32_t i, c, s = 0;
for (i = n; i > 0; --i) {
c = (uint32_t)(*b++);
s = (s << 8) ^ crctab[(s >> 24) ^ c];
}
uint32_t s = 0;
memcrc_r(&s, b, n);
/* Extend with the length of the string. */
while (n != 0) {
c = n & 0377;
register uint32_t c = n & 0377;
n >>= 8;
s = (s << 8) ^ crctab[(s >> 24) ^ c];
}
......@@ -100,11 +97,11 @@ memcrc_r(uint32_t *state, const unsigned char *block, size_t block_len)
*/
register uint32_t i, c, s = *state;
register uint32_t c, s = *state;
register size_t n = block_len;
register const unsigned char *b = block;
for (i = n; i > 0; --i) {
for (; n > 0; --n) {
c = (uint32_t)(*b++);
s = (s << 8) ^ crctab[(s >> 24) ^ c];
}
......@@ -172,7 +169,7 @@ uint32_t
memcrc_finish(uint32_t *state, off_t total_size)
{
register uint32_t c, s = *state;
register off_t n = total_size;
register uint64_t n = (uint64_t)total_size;
/* Extend with the length of the string. */
while (n != 0) {
......
#ifdef HAVE_CONFIG_H
#include "config.h"
# include "config.h"
#endif
#include <inttypes.h>
......
#ifndef HAVE_CONFIG_H
#include "config.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include "ensure_array_size.h"
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include "cdi.h"
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment