소스 검색

Don't panic when a DefBuffer contains less bytes than its size

If a DefBuffer contains less bytes than its size, the remaining bytes should
be initialized to `0`. I overlooked that `copy_from_slice` requires that
its two slices are the same size, and so this panics in these cases. This
was picked up by fuzzing.
Isaac Woods 4 년 전
부모
커밋
0c64768a9e
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      aml/src/type2.rs

+ 1 - 1
aml/src/type2.rs

@@ -108,7 +108,7 @@ where
                     }
 
                     let mut buffer = vec![0; buffer_size];
-                    buffer.copy_from_slice(bytes);
+                    (&mut buffer[0..bytes.len()]).copy_from_slice(bytes);
                     (Ok(buffer), context)
                 })
             }),