From b5df37a79957b13b9007b7a93f40517f3a1e660d Mon Sep 17 00:00:00 2001 From: Michal Simon Date: Tue, 5 Jan 2021 16:36:08 +0100 Subject: [PATCH] [XrdEc] Verify stripe integrity. --- src/XrdEc/XrdEcReader.hh | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/XrdEc/XrdEcReader.hh b/src/XrdEc/XrdEcReader.hh index ff7f73b757d..5c8c9fc4282 100644 --- a/src/XrdEc/XrdEcReader.hh +++ b/src/XrdEc/XrdEcReader.hh @@ -359,7 +359,45 @@ namespace XrdEc buffer.resize( rdsize ); // issue the read request XrdCl::Async( XrdCl::ReadFrom( *zipptr, fn, 0, buffer.size(), buffer.data() ) >> - [cb]( XrdCl::XRootDStatus &st, XrdCl::ChunkInfo &ch ) { /*TODO verify integrity!!!*/ cb( st, ch.length ); } ); + [zipptr, fn, cb]( XrdCl::XRootDStatus &st, XrdCl::ChunkInfo &ch ) + { + //--------------------------------------------------- + // If read failed there's nothing to do, just pass the + // status to user callback + //--------------------------------------------------- + if( !st.IsOK() ) + { + cb( st, 0 ); + return; + } + //--------------------------------------------------- + // Get the checksum for the read data + //--------------------------------------------------- + uint32_t orgcksum = 0; + auto s = zipptr->GetCRC32( fn, orgcksum ); + //--------------------------------------------------- + // If we cannot extract the checksum assume the data + // are corrupted + //--------------------------------------------------- + if( !st.IsOK() ) + { + cb( st, 0 ); + return; + } + //--------------------------------------------------- + // Verify data integrity + //--------------------------------------------------- + uint32_t cksum = crc32c( 0, ch.buffer, ch.length ); + if( orgcksum != cksum ) + { + cb( XrdCl::XRootDStatus( XrdCl::stError, XrdCl::errDataError ), 0 ); + return; + } + //--------------------------------------------------- + // All is good, we can call now the user callback + //--------------------------------------------------- + cb( XrdCl::XRootDStatus(), ch.length ); + } ); } XrdCl::Pipeline ReadMetadata( size_t index )