[jacorb-developer] Error in String to byte conversion in CDROutputSream and byte to String conversion in CDRInputStream class

Gotthard Witsch Gotthard.Witsch at ith-icoserve.com
Thu Feb 13 10:57:13 CET 2014


Dear developers,

As we are having problems with sending and receiving Strings with JacOrb 3.3 in our java application, I started to analyse your code.
I got aware of  two classes that cause errors in my opinion: org.jacorb.orb.CDROutputStream and org.jacorb.orb.CDRInputStream.
Let's start with CDROutpuStream:
The conversion from String to byte array is done in write_string methode in org.jacorb.CDROutputStream. However I think there are several bugs in this method:
If we set codesetEnabled to true with the property jacorb.codeset at initialization, we can transmit Strings with ASCII, 2 byte and 3 byte characters. The transmission of 4 byte characters is not possible because the implementation of org.jacorb.orb.giop.CodeSet.Utf8CodeSet.write_char, that does not handle 4 byte characters. We've already opened a bug in your bugtracker but did not receive any feedback - http://www.jacorb.org/bugzilla/show_bug.cgi?id=969
Refering to the documentation we are not supposed to use jacorb.codeset as Java receives UTF-8 Strings and the CORBA backend expects UTF-8 encoded Strings. So in my opinion there's no need for conversion. However if we turn jacorb.codeset off we can only transmit ASCII Strings, every other character not being part of ASCII Standard is encoded wrong. I think the problem is produced at line number 925 in org.jacorb.orb.CDROutputStream: value.getBytes(0, valueLength, buffer, pos); The used method getBytes is deprecated, due to the fact that it does not properly convert characters into bytes. In the comment the line before it is mentioned that this methode is explicitly used for better speed. Can you tell me why this method is better than String.getBytes(String charsetName)?

On the outer side there could be a logical bug in the class org.jacorb.orb.CDRInputStream:
In the method read_string the received bytes are converted to a String. In line number 1247 codesetEnable is checked. If set to true a String is created with the following statement:
result = new String (buffer, start, size, codeSet.getName()); -> JVM decides on how to create the String!
If codesetEnabled is set to false than a conversion is done with a loop in line number 1267:  buf[i] = (char)(0xff & buffer[start + i]); After the conversion the String is created with the resulting byte array.

So if I understood your code correct the if block should be something like this:

if (codesetEnable) {
                // convert bytes with loop from line 1267
} else {
                // create String and let JVM decide how to do this, with code from line 1252
}

Can you give me some feedback if I'm wrong or if that's really a bug.

At initializing JacOrb we set the following properties:
"ORBInitRef.NameService" "corbaloc:" + iiop:url_to_nameservice
"org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB"#
"org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton"
"jacorb.codeset", "on"
"jacorb.security.support_ssl", "on"
"jacorb.security.jsse.trustees_from_ks", "on"
"jacorb.security.keystore", keyStorePath
"jacorb.security.keystore_password", keystorepass
"jacorb.security.ssl.client.supported_options", "60"
"jacorb.security.ssl.client.required_options", "01"
"jacorb.ssl.socket_factory", "org.jacorb.security.ssl.sun_jsse.SSLSocketFactory"
"jacorb.ssl.server_socket_factory", "org.jacorb.security.ssl.sun_jsse.SSLServerSocketFactory"
"jacorb.maxManagedBufSize", "23"
"jacorb.reference_caching", "true"
"jacorb.retries", "30"
"jacorb.retry_interval", "2000"

Sincerely,

Gotthard Witsch
Syngo Share Software Development

E-Mail: gotthard.witsch at ith-icoserve.com<mailto:stefan.daxenbichler at ith-icoserve.com>
_____________________________________
ITH icoserve technology for healthcare GmbH
a siemens company - H CX HS INT CES ITH
Innrain 98, 6020 Innsbruck, Österreich - www.ith-icoserve.com<http://www.ith-icoserve.com/>
Rechtsform: Gesellschaft mit beschränkter Haftung - Firmensitz: 6020 Innsbruck, Innrain 98
Firmenbuchnummer: FN 174117f - Firmenbuchgericht: Innsbruck - DVR: 0983039



More information about the jacorb-developer mailing list