Skip to content

Commit

Permalink
Fix for Bug#25438355, Improper automatic deserialization of binary data.
Browse files Browse the repository at this point in the history
 Please enter the commit message for your changes. Lines starting
  • Loading branch information
fjssilva committed Jan 31, 2017
1 parent 7500e73 commit 6189e71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# $Id$
mm-dd-yy - Version 5.1.41

- Fix for Bug#25438355, Improper automatic deserialization of binary data.

- Fix for Bug#70785 (17756825), MySQL Connector/J inconsistent init state for autocommit.

- Fix for Bug#75615 (21181249), Incorrect implementation of Connection.setNetworkTimeout().
Expand Down
36 changes: 19 additions & 17 deletions src/com/mysql/jdbc/ResultSetImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand Down Expand Up @@ -3429,24 +3429,26 @@ private String getNativeConvertToString(int columnIndex, Field field) throws SQL
byte[] data = getBytes(columnIndex);
Object obj = data;

if ((data != null) && (data.length >= 2)) {
if ((data[0] == -84) && (data[1] == -19)) {
// Serialized object?
try {
ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
ObjectInputStream objIn = new ObjectInputStream(bytesIn);
obj = objIn.readObject();
objIn.close();
bytesIn.close();
} catch (ClassNotFoundException cnfe) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Class_not_found___91") + cnfe.toString()
+ Messages.getString("ResultSet._while_reading_serialized_object_92"), getExceptionInterceptor());
} catch (IOException ex) {
obj = data; // not serialized?
if (this.connection.getAutoDeserialize()) {
if ((data != null) && (data.length >= 2)) {
if ((data[0] == -84) && (data[1] == -19)) {
// Serialized object?
try {
ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
ObjectInputStream objIn = new ObjectInputStream(bytesIn);
obj = objIn.readObject();
objIn.close();
bytesIn.close();
} catch (ClassNotFoundException cnfe) {
throw SQLError.createSQLException(Messages.getString("ResultSet.Class_not_found___91") + cnfe.toString()
+ Messages.getString("ResultSet._while_reading_serialized_object_92"), getExceptionInterceptor());
} catch (IOException ex) {
obj = data; // not serialized?
}
}
}

return obj.toString();
return obj.toString();
}
}

return extractStringFromNativeColumn(columnIndex, mysqlType);
Expand Down

0 comments on commit 6189e71

Please sign in to comment.