diff --git a/CHANGES b/CHANGES index 9e464a232..57b08427f 100644 --- a/CHANGES +++ b/CHANGES @@ -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(). diff --git a/src/com/mysql/jdbc/ResultSetImpl.java b/src/com/mysql/jdbc/ResultSetImpl.java index d6cda5973..44a6e2c2a 100644 --- a/src/com/mysql/jdbc/ResultSetImpl.java +++ b/src/com/mysql/jdbc/ResultSetImpl.java @@ -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 , like most MySQL Connectors. @@ -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);