Protryon / klickhouse

Rust crate for accessing Clickhouse

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

some protocol reads/writes not using little-endian i32 serialization

stevelr opened this issue · comments

I noticed a few of the read_i32 and write_i32 calls don't force the little-endian variants. Since I just found this by code inspection and my platform is little-endian, I can't easily test whether it's an actual bug or not. I just wanted to flag these in case they were an oversight.

diff --git a/klickhouse/src/block.rs b/klickhouse/src/block.rs
index 24911d9..894bed8 100644
--- a/klickhouse/src/block.rs
+++ b/klickhouse/src/block.rs
@@ -37,7 +37,7 @@ impl BlockInfo {
                     new.is_overflows = reader.read_u8().await? != 0;
                 }
                 2 => {
-                    new.bucket_num = reader.read_i32().await?;
+                    new.bucket_num = reader.read_i32_le().await?;
                 }
                 field_num => {
                     return Err(KlickhouseError::ProtocolError(format!(
@@ -56,7 +56,7 @@ impl BlockInfo {
             .write_u8(if self.is_overflows { 1 } else { 2 })
             .await?;
         writer.write_var_uint(2).await?;
-        writer.write_i32(self.bucket_num).await?;
+        writer.write_i32_le(self.bucket_num).await?;
         writer.write_var_uint(0).await?;
         Ok(())
     }
diff --git a/klickhouse/src/internal_client_in.rs b/klickhouse/src/internal_client_in.rs
index 94d419a..85874a4 100644
--- a/klickhouse/src/internal_client_in.rs
+++ b/klickhouse/src/internal_client_in.rs
@@ -34,7 +34,7 @@ impl<R: ClickhouseRead> InternalClientIn<R> {
     }

     async fn read_exception(&mut self) -> Result<ServerException> {
-        let code = self.reader.read_i32().await?;
+        let code = self.reader.read_i32_le().await?;
         let name = self.reader.read_string().await?;
         let message = self.reader.read_string().await?;
         let stack_trace = self.reader.read_string().await?;

Looking into CH server source, it seems you are right. Will Update.