jklamer commented on code in PR #1914:
URL: https://github.com/apache/avro/pull/1914#discussion_r997703818


##########
lang/rust/avro/src/reader.rs:
##########
@@ -396,9 +396,9 @@ impl GenericSingleObjectReader {
 
     pub fn read_value<R: Read>(&self, reader: &mut R) -> AvroResult<Value> {
         let mut header: [u8; 10] = [0; 10];
-        match reader.read(&mut header) {
-            Ok(size) => {
-                if size == 10 && self.expected_header == header {
+        match reader.read_exact(&mut header) {

Review Comment:
   very simple fix. I like. 



##########
lang/rust/avro/src/reader.rs:
##########
@@ -396,9 +396,9 @@ impl GenericSingleObjectReader {
 
     pub fn read_value<R: Read>(&self, reader: &mut R) -> AvroResult<Value> {
         let mut header: [u8; 10] = [0; 10];
-        match reader.read(&mut header) {
-            Ok(size) => {
-                if size == 10 && self.expected_header == header {
+        match reader.read_exact(&mut header) {
+            Ok(_) => {

Review Comment:
   What would you feel about pattern matching to 10?
   Along with a follow up error for more details, something like:
   ```
   Ok(10) => { //this case},
   Ok(x) => Err(Error::InompleteHeader(x)),
   Err(io_error)=> Err(Error::ReadHeader(io_error)), //existing below
   ```



##########
lang/rust/avro/src/reader.rs:
##########
@@ -804,6 +804,38 @@ mod tests {
         assert_eq!(expected_value, val);
     }
 
+    #[test]
+    fn test_avro_3507_single_object_reader_incomplete_reads() {
+        let obj = TestSingleObjectReader {
+            a: 42,
+            b: 3.33,
+            c: vec!["cat".into(), "dog".into()],
+        };
+        let mut to_read_1 = Vec::<u8>::new();
+        to_read_1.extend_from_slice(&[0xC3, 0x01]);
+        let mut to_read_2 = Vec::<u8>::new();
+        to_read_2.extend_from_slice(
+            &TestSingleObjectReader::get_schema()
+                .fingerprint::<Rabin>()
+                .bytes[..],
+        );
+        let mut to_read_3 = Vec::<u8>::new();
+        encode(
+            &obj.clone().into(),
+            &TestSingleObjectReader::get_schema(),
+            &mut to_read_3,
+        )
+        .expect("Encode should succeed");
+        let mut to_read = 
(&to_read_1[..]).chain(&to_read_2[..]).chain(&to_read_3[..]);

Review Comment:
   interesting. `the` method would fail in this case? not would I would expect. 
Good catch!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to