From 6150854bd2cb431f23956410adf9714cb4086517 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Sat, 19 Feb 2022 13:10:23 +0000 Subject: [PATCH] Bumped crc --- Cargo.toml | 2 +- src/io/avro/read/decompress.rs | 5 ++++- src/io/avro/write/compress.rs | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index db0e2e89bc6..90a15f8c2ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,7 @@ avro-schema = { version = "0.2", optional = true } # compression of avro libflate = { version = "1.1.1", optional = true } snap = { version = "1", optional = true } -crc = { version = "1", optional = true } +crc = { version = "2", optional = true } # async avro async-stream = { version = "0.3.2", optional = true } diff --git a/src/io/avro/read/decompress.rs b/src/io/avro/read/decompress.rs index 03fb6261bd6..30f28de9226 100644 --- a/src/io/avro/read/decompress.rs +++ b/src/io/avro/read/decompress.rs @@ -9,6 +9,8 @@ use super::super::{Block, CompressedBlock}; use super::BlockStreamIterator; use super::Compression; +const CRC_TABLE: crc::Crc = crc::Crc::::new(&crc::CRC_32_ISO_HDLC); + /// Decompresses an Avro block. /// Returns whether the buffers where swapped. pub fn decompress_block( @@ -46,7 +48,8 @@ pub fn decompress_block( .map_err(|e| ArrowError::ExternalFormat(e.to_string()))?; let expected_crc = u32::from_be_bytes([crc[0], crc[1], crc[2], crc[3]]); - let actual_crc = crc::crc32::checksum_ieee(decompressed); + + let actual_crc = CRC_TABLE.checksum(decompressed); if expected_crc != actual_crc { return Err(ArrowError::ExternalFormat( "The crc of snap-compressed block does not match".to_string(), diff --git a/src/io/avro/write/compress.rs b/src/io/avro/write/compress.rs index 1e35311ef81..4a98f78860a 100644 --- a/src/io/avro/write/compress.rs +++ b/src/io/avro/write/compress.rs @@ -5,6 +5,8 @@ use crate::error::Result; use super::Compression; use super::{Block, CompressedBlock}; +const CRC_TABLE: crc::Crc = crc::Crc::::new(&crc::CRC_32_ISO_HDLC); + /// Compresses a [`Block`] to a [`CompressedBlock`]. pub fn compress( block: &mut Block, @@ -42,8 +44,7 @@ pub fn compress( .map_err(|e| crate::error::ArrowError::ExternalFormat(e.to_string()))?; compressed.truncate(compressed_bytes); - let crc = crc::crc32::checksum_ieee(block); - compressed.extend(crc.to_be_bytes()); + compressed.extend(CRC_TABLE.checksum(block).to_be_bytes()); Ok(false) } #[cfg(not(feature = "io_avro_compression"))]