From bbae27f30f41088f3f2db45e87e1fff7e2d14b2b Mon Sep 17 00:00:00 2001 From: Pilmo Date: Wed, 18 Oct 2023 13:53:20 +0900 Subject: [PATCH 1/2] Add error logging for crc32 validation failures Co-authored-by: jaehyeonpy jaehyeonpy@gmail.com Co-authored-by: davinc71998 davinc71998@gmail.com --- pymysqlreplication/event.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pymysqlreplication/event.py b/pymysqlreplication/event.py index c47b646e..10841fc4 100644 --- a/pymysqlreplication/event.py +++ b/pymysqlreplication/event.py @@ -3,6 +3,7 @@ import datetime import decimal import zlib +import logging from pymysqlreplication.constants.STATUS_VAR_KEY import * from pymysqlreplication.exceptions import StatusVariableMismatch @@ -57,7 +58,14 @@ def _verify_event(self): data = self.packet.read(19 + self.event_size) footer = self.packet.read(4) byte_data = zlib.crc32(data).to_bytes(4, byteorder="little") - self._is_event_valid = True if byte_data == footer else False + if byte_data == footer: + self._is_event_valid = True + else: + self._is_event_valid = False + logging.error( + f"An CRC32 has failed for the event type {self.event_type}, " + "indicating a potential integrity issue with the data." + ) self.packet.read_bytes -= 19 + self.event_size + 4 self.packet.rewind(20) From e8bb23578a82c574034b7d83e5d51ea75243acf7 Mon Sep 17 00:00:00 2001 From: Pilmo Date: Thu, 19 Oct 2023 13:35:50 +0900 Subject: [PATCH 2/2] Simplify code to improve readability --- pymysqlreplication/event.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pymysqlreplication/event.py b/pymysqlreplication/event.py index 10841fc4..82b89974 100644 --- a/pymysqlreplication/event.py +++ b/pymysqlreplication/event.py @@ -58,10 +58,8 @@ def _verify_event(self): data = self.packet.read(19 + self.event_size) footer = self.packet.read(4) byte_data = zlib.crc32(data).to_bytes(4, byteorder="little") - if byte_data == footer: - self._is_event_valid = True - else: - self._is_event_valid = False + self._is_event_valid = True if byte_data == footer else False + if not self._is_event_valid: logging.error( f"An CRC32 has failed for the event type {self.event_type}, " "indicating a potential integrity issue with the data."