@@ -155,10 +155,10 @@ func (c *Conn) handleStmtExecute(data []byte) (*mysql.Result, error) {
155155 pos += paramNum << 1
156156
157157 paramValues = data [pos :]
158- }
159158
160- if err := c .bindStmtArgs (s , nullBitmaps , paramTypes , paramValues ); err != nil {
161- return nil , errors .Trace (err )
159+ if err := c .bindStmtArgs (s , nullBitmaps , paramTypes , paramValues ); err != nil {
160+ return nil , errors .Trace (err )
161+ }
162162 }
163163 }
164164
@@ -176,6 +176,14 @@ func (c *Conn) handleStmtExecute(data []byte) (*mysql.Result, error) {
176176func (c * Conn ) bindStmtArgs (s * Stmt , nullBitmap , paramTypes , paramValues []byte ) error {
177177 args := s .Args
178178
179+ // Every param should have a type-and-flag of 2 bytes
180+ // 0xfe80 == Type 0xfe and Flag 0x80
181+ // The flag only has one bit and that indicates if it is unsigned or not.
182+ // Types are 1 byte, but might grow into the 7 unused bits in the future.
183+ if len (paramTypes )/ 2 != s .Params {
184+ return mysql .ErrMalformPacket
185+ }
186+
179187 pos := 0
180188
181189 var v []byte
@@ -190,7 +198,7 @@ func (c *Conn) bindStmtArgs(s *Stmt, nullBitmap, paramTypes, paramValues []byte)
190198 }
191199
192200 tp := paramTypes [i << 1 ]
193- isUnsigned := (paramTypes [(i << 1 )+ 1 ] & 0x80 ) > 0
201+ isUnsigned := (paramTypes [(i << 1 )+ 1 ] & mysql . PARAM_UNSIGNED ) > 0
194202
195203 switch tp {
196204 case mysql .MYSQL_TYPE_NULL :
0 commit comments