@@ -696,6 +696,13 @@ pub fn copy_and_replace_cstring_placeholder(
696696 let old_prefix = prefix_placeholder. as_bytes ( ) ;
697697 let new_prefix = target_prefix. as_bytes ( ) ;
698698
699+ if new_prefix. len ( ) > old_prefix. len ( ) {
700+ return Err ( std:: io:: Error :: new (
701+ std:: io:: ErrorKind :: InvalidData ,
702+ "target prefix cannot be longer than the placeholder prefix" ,
703+ ) ) ;
704+ }
705+
699706 let finder = memchr:: memmem:: Finder :: new ( old_prefix) ;
700707
701708 loop {
@@ -842,8 +849,6 @@ mod test {
842849 "cruel" ,
843850 b"12345Hello, cruel world!\x00 \x00 \x00 \x00 6789"
844851 ) ]
845- #[ case( b"short\x00 " , "short" , "verylong" , b"veryl\x00 " ) ]
846- #[ case( b"short1234\x00 " , "short" , "verylong" , b"verylong1\x00 " ) ]
847852 pub fn test_copy_and_replace_binary_placeholder (
848853 #[ case] input : & [ u8 ] ,
849854 #[ case] prefix_placeholder : & str ,
@@ -866,6 +871,26 @@ mod test {
866871 assert_eq ! ( & output. into_inner( ) , expected_output) ;
867872 }
868873
874+ #[ rstest]
875+ #[ case( b"short\x00 " , "short" , "verylong" ) ]
876+ #[ case( b"short1234\x00 " , "short" , "verylong" ) ]
877+ pub fn test_shorter_binary_placeholder (
878+ #[ case] input : & [ u8 ] ,
879+ #[ case] prefix_placeholder : & str ,
880+ #[ case] target_prefix : & str ,
881+ ) {
882+ assert ! ( target_prefix. len( ) > prefix_placeholder. len( ) ) ;
883+
884+ let mut output = Cursor :: new ( Vec :: new ( ) ) ;
885+ let result = super :: copy_and_replace_cstring_placeholder (
886+ input,
887+ & mut output,
888+ prefix_placeholder,
889+ target_prefix,
890+ ) ;
891+ assert ! ( result. is_err( ) ) ;
892+ }
893+
869894 #[ test]
870895 fn replace_binary_path_var ( ) {
871896 let input =
0 commit comments