pablomelo / subethasmtp

Automatically exported from code.google.com/p/subethasmtp
Other
0 stars 0 forks source link

bug in receivedheaderstream #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://www.subethamail.org/se/archive_msg.jsp?msgId=59719

Hi everyone,

Great project!
I'm pretty sure that ReceivedHeaderStream.read(byte[] b, int off, int  
len) works incorrectly when off > 0.
If you try the following code:

    int BUF_SIZE = 10000;
    int offset = 10;
         ByteArrayInputStream in = new ByteArrayInputStream("hello  
world".getBytes());
         ReceivedHeaderStream hdrIS = new ReceivedHeaderStream(in,  
"ehlo", InetAddress.getLocalHost(), "foo");
         byte[] buf = new byte[BUF_SIZE];
         int len = hdrIS.read(buf, offset, BUF_SIZE-offset);
         System.out.println(new String(buf, offset, len));

It prints:

  Received: from ehlo (192.168.20.2 [kasper-langers-macbook-pro.local/ 
192.168.20.2])
         by foo with SMTP;
         Thu, 11 Feb 2010 10:14:57 +01hello world

instead of the expected:

Received: from ehlo (192.168.20.2 [kasper-langers-macbook-pro.local/ 
192.168.20.2])
         by foo with SMTP;
         Thu, 11 Feb 2010 10:15:43 +0100 (CET)
hello world

If you change the offset to 0 the output is correct.

FIX:
Change ReceivedHeaderStream:96 from
int additionalRead = super.read(b, countRead, remainder);
to:
int additionalRead = super.read(b, off + countRead, remainder);

Cheers,

-Kasper

Original issue reported on code.google.com by latch...@gmail.com on 11 Feb 2010 at 7:43

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r367.

Original comment by latch...@gmail.com on 11 Feb 2010 at 7:43