Skip to content
This repository was archived by the owner on Oct 10, 2019. It is now read-only.

Commit 1e90401

Browse files
committed
Check for overflow
1 parent 29db483 commit 1e90401

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

postgres-derive-codegen/src/tosql.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ fn composite_to_sql_body(ctx: &mut ExtCtxt,
166166
match try!(r) {
167167
::postgres::types::IsNull::Yes => try!(write_be_i32(out, -1)),
168168
::postgres::types::IsNull::No => {
169-
try!(write_be_i32(out, buf.len() as i32));
169+
let len = if buf.len() > i32::max_value() as usize {
170+
return ::std::result::Result::Err(::postgres::error::Error::Conversion(
171+
"value too large to transmit".into()));
172+
} else {
173+
buf.len() as i32
174+
};
175+
try!(write_be_i32(out, len));
170176
try!(::std::io::Write::write_all(out, &buf));
171177
}
172178
}

0 commit comments

Comments
 (0)