Bug in jinterface

Raimo Niskanen raimo@REDACTED
Tue Aug 23 12:16:25 CEST 2005


This bug is fixed in R10B (jinterface-1.3) and later:

  public void write_string(String s) { 
    int len = s.length();
    
    switch(len) {
    case 0:
      this.write_nil();
      break;
    default:
      byte[] bytebuf = s.getBytes();

      /* switch to se if the length of
	 the byte array is equal to the 
	 length of the list, or if the string is too long
	 for the stream protocol */
      if ((bytebuf.length == len) && (len <= 65535)) { /* Usual */
	this.write1(OtpExternal.stringTag);
	this.write2BE(len);
	this.writeN(bytebuf);
      } 
      else { /* Unicode */
	char[] charbuf = s.toCharArray();
	
	this.write_list_head(len);
	
	for(int i = 0; i<len; i++)
	  this.write_char(charbuf[i]);
	
	this.write_nil();
      }
    }
  }

Thank you for finding it anyway!



vlad_dumitrescu@REDACTED (Vlad Dumitrescu) writes:

> Hi,
> 
> The OtpOutputStream implementation in jinterface is not conforming to
> the external distribution format: method write_string doesn't check if
> the length is >= 65536, when the sitring should be output with a
> listTag, not a stringTag.
> 
> The patch is (sorry, but I have a modified version of the file and the
> line numbers don't match)
> 
> -            if (bytebuf.length == len && len < 65535)
> +            if (bytebuf.length == len)
> 
> regards,
> Vlad
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-bugs mailing list