You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dan Armbrust (JIRA)" <ji...@apache.org> on 2008/01/04 20:47:35 UTC

[jira] Created: (NET-181) tftp client limited to ~32 MB file sizes

tftp client limited to ~32 MB file sizes
----------------------------------------

                 Key: NET-181
                 URL: https://issues.apache.org/jira/browse/NET-181
             Project: Commons Net
          Issue Type: Improvement
         Environment: All
            Reporter: Dan Armbrust
            Priority: Minor


I just noticed that the TFTPClient class does not support a block wraparound - hence, when the block number exceeds the max allowed by the rfc (65535) - about a 32 mb file - bad things will happen.

I can't find any rfc that specifies how the wraparound is supposed to occur, but this wiki page mentions it:

http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol

And I am working on implementing a TFTPServer - and in my tests with the tftp client that is shipped with fedora, I have determined that that tftp client expects the next block number after 65535 to be 0.

So it appears that the TFTPClient should wrap its block number so that it properly supports larger files.



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (NET-181) tftp client limited to ~32 MB file sizes

Posted by "Rory Winston (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12556750#action_12556750 ] 

Rory Winston commented on NET-181:
----------------------------------

Is that all that needs to be done (making the block number wrap using % 2^16-1)?

Or is there more that needs to be done here?

> tftp client limited to ~32 MB file sizes
> ----------------------------------------
>
>                 Key: NET-181
>                 URL: https://issues.apache.org/jira/browse/NET-181
>             Project: Commons Net
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Dan Armbrust
>            Priority: Minor
>
> I just noticed that the TFTPClient class does not support a block wraparound - hence, when the block number exceeds the max allowed by the rfc (65535) - about a 32 mb file - bad things will happen.
> I can't find any rfc that specifies how the wraparound is supposed to occur, but this wiki page mentions it:
> http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
> And I am working on implementing a TFTPServer - and in my tests with the tftp client that is shipped with fedora, I have determined that that tftp client expects the next block number after 65535 to be 0.
> So it appears that the TFTPClient should wrap its block number so that it properly supports larger files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (NET-181) tftp client limited to ~32 MB file sizes

Posted by "Dan Armbrust (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12571802#action_12571802 ] 

Dan Armbrust commented on NET-181:
----------------------------------

Here is a patch which implements block wrapping.

I tested this against the tftpd server in Ubuntu, and against my own tftp server which I will be attaching shortly.


{noformat}
Index: TFTPClient.java
===================================================================
--- .	(revision 630373)
+++ .	(working copy)
@@ -231,6 +231,12 @@
                                 throw e;
                             }
                             ++block;
+                            if (block > 65535)
+							{
+								// wrap the block number
+								block = 0;
+							}
+                            
                             break _receivePacket;
                         }
                         else
@@ -237,7 +243,7 @@
                         {
                             discardPackets();
 
-                            if (lastBlock == (block - 1))
+                            if (lastBlock == (block == 0 ? 65535 : (block - 1)))
                                 continue _sendPacket;  // Resend last acknowledgement.
 
                             continue _receivePacket; // Start fetching packets again.
@@ -464,6 +470,11 @@
                         if (lastBlock == block)
                         {
                             ++block;
+                            if (block > 65535)
+							{
+								// wrap the block number
+								block = 0;
+							}
                             if (lastAckWait) {
                                 
                               break _sendPacket;
@@ -476,7 +487,7 @@
                         {
                             discardPackets();
 
-                            if (lastBlock == (block - 1))
+                            if (lastBlock == (block == 0 ? 65535 : (block - 1)))
                                 continue _sendPacket;  // Resend last acknowledgement.
 
                             continue _receivePacket; // Start fetching packets again.
{noformat}


> tftp client limited to ~32 MB file sizes
> ----------------------------------------
>
>                 Key: NET-181
>                 URL: https://issues.apache.org/jira/browse/NET-181
>             Project: Commons Net
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Dan Armbrust
>            Priority: Minor
>
> I just noticed that the TFTPClient class does not support a block wraparound - hence, when the block number exceeds the max allowed by the rfc (65535) - about a 32 mb file - bad things will happen.
> I can't find any rfc that specifies how the wraparound is supposed to occur, but this wiki page mentions it:
> http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
> And I am working on implementing a TFTPServer - and in my tests with the tftp client that is shipped with fedora, I have determined that that tftp client expects the next block number after 65535 to be 0.
> So it appears that the TFTPClient should wrap its block number so that it properly supports larger files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (NET-181) tftp client limited to ~32 MB file sizes

Posted by "Dan Armbrust (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12571803#action_12571803 ] 

armbrust edited comment on NET-181 at 2/23/08 3:31 PM:
-----------------------------------------------------------

Attached file is same patch as above.

      was (Author: armbrust):
    Same patch as above.
  
> tftp client limited to ~32 MB file sizes
> ----------------------------------------
>
>                 Key: NET-181
>                 URL: https://issues.apache.org/jira/browse/NET-181
>             Project: Commons Net
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Dan Armbrust
>            Priority: Minor
>         Attachments: TFTPClient.java.patch
>
>
> I just noticed that the TFTPClient class does not support a block wraparound - hence, when the block number exceeds the max allowed by the rfc (65535) - about a 32 mb file - bad things will happen.
> I can't find any rfc that specifies how the wraparound is supposed to occur, but this wiki page mentions it:
> http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
> And I am working on implementing a TFTPServer - and in my tests with the tftp client that is shipped with fedora, I have determined that that tftp client expects the next block number after 65535 to be 0.
> So it appears that the TFTPClient should wrap its block number so that it properly supports larger files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (NET-181) tftp client limited to ~32 MB file sizes

Posted by "Dan Armbrust (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/NET-181?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dan Armbrust updated NET-181:
-----------------------------

    Attachment: TFTPClient.java.patch

Same patch as above.

> tftp client limited to ~32 MB file sizes
> ----------------------------------------
>
>                 Key: NET-181
>                 URL: https://issues.apache.org/jira/browse/NET-181
>             Project: Commons Net
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Dan Armbrust
>            Priority: Minor
>         Attachments: TFTPClient.java.patch
>
>
> I just noticed that the TFTPClient class does not support a block wraparound - hence, when the block number exceeds the max allowed by the rfc (65535) - about a 32 mb file - bad things will happen.
> I can't find any rfc that specifies how the wraparound is supposed to occur, but this wiki page mentions it:
> http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
> And I am working on implementing a TFTPServer - and in my tests with the tftp client that is shipped with fedora, I have determined that that tftp client expects the next block number after 65535 to be 0.
> So it appears that the TFTPClient should wrap its block number so that it properly supports larger files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (NET-181) tftp client limited to ~32 MB file sizes

Posted by "Dan Armbrust (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12556755#action_12556755 ] 

Dan Armbrust commented on NET-181:
----------------------------------

In my TFTP Server, simply wrapping the block number worked.  So yes, I think it is just that simple.  That said, I would have felt better if I could have found an RFC that said that wrapping the block number is expected practice... My only confirmation was sampling 1 other tftp client, to see what it did.

I didn't look through the tftp client source in detail to see if there would be any negative side-effects to wrapping the block number, at a glance, it didn't look like there would be.

> tftp client limited to ~32 MB file sizes
> ----------------------------------------
>
>                 Key: NET-181
>                 URL: https://issues.apache.org/jira/browse/NET-181
>             Project: Commons Net
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Dan Armbrust
>            Priority: Minor
>
> I just noticed that the TFTPClient class does not support a block wraparound - hence, when the block number exceeds the max allowed by the rfc (65535) - about a 32 mb file - bad things will happen.
> I can't find any rfc that specifies how the wraparound is supposed to occur, but this wiki page mentions it:
> http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
> And I am working on implementing a TFTPServer - and in my tests with the tftp client that is shipped with fedora, I have determined that that tftp client expects the next block number after 65535 to be 0.
> So it appears that the TFTPClient should wrap its block number so that it properly supports larger files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (NET-181) tftp client limited to ~32 MB file sizes

Posted by "Rory Winston (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/NET-181?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rory Winston closed NET-181.
----------------------------

       Resolution: Fixed
    Fix Version/s: 2.0
                   1.5

> tftp client limited to ~32 MB file sizes
> ----------------------------------------
>
>                 Key: NET-181
>                 URL: https://issues.apache.org/jira/browse/NET-181
>             Project: Commons Net
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Dan Armbrust
>            Priority: Minor
>             Fix For: 1.5, 2.0
>
>         Attachments: TFTPClient.java.patch
>
>
> I just noticed that the TFTPClient class does not support a block wraparound - hence, when the block number exceeds the max allowed by the rfc (65535) - about a 32 mb file - bad things will happen.
> I can't find any rfc that specifies how the wraparound is supposed to occur, but this wiki page mentions it:
> http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
> And I am working on implementing a TFTPServer - and in my tests with the tftp client that is shipped with fedora, I have determined that that tftp client expects the next block number after 65535 to be 0.
> So it appears that the TFTPClient should wrap its block number so that it properly supports larger files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (NET-181) tftp client limited to ~32 MB file sizes

Posted by "Rory Winston (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12569767#action_12569767 ] 

Rory Winston commented on NET-181:
----------------------------------

Have you got a patch for this? I assume it may just be the following code that needs to be altered?

/***
     * Creates a data packet to be sent to a host at a given port
     * with a given block number.  The actual data to be sent is passed as
     * an array, an offset, and a length.  The offset is the offset into
     * the byte array where the data starts.  The length is the length of
     * the data.  If the length is greater than MAX_DATA_LENGTH, it is
     * truncated.
     * <p>
     * @param destination  The host to which the packet is going to be sent.
     * @param port  The port to which the packet is going to be sent.
     * @param blockNumber The block number of the data.
     * @param data The byte array containing the data.
     * @param offset The offset into the array where the data starts.
     * @param length The length of the data.
     ***/
    public TFTPDataPacket(InetAddress destination, int port, int blockNumber,
                          byte[] data, int offset, int length)
    {
        super(TFTPPacket.DATA, destination, port);

        _blockNumber = blockNumber;
        _data = data;
        _offset = offset;

        if (length > MAX_DATA_LENGTH)
            _length = MAX_DATA_LENGTH;
        else
            _length = length;
    }

    public TFTPDataPacket(InetAddress destination, int port, int blockNumber,
                          byte[] data)
    {
        this(destination, port, blockNumber, data, 0, data.length);
    }


    /***
     * Creates a data packet based from a received
     * datagram.  Assumes the datagram is at least length 4, else an
     * ArrayIndexOutOfBoundsException may be thrown.
     * <p>
     * @param datagram  The datagram containing the received data.
     * @throws TFTPPacketException  If the datagram isn't a valid TFTP
     *         data packet.
     ***/
    TFTPDataPacket(DatagramPacket datagram) throws TFTPPacketException
    {
        super(TFTPPacket.DATA, datagram.getAddress(), datagram.getPort());

        _data = datagram.getData();
        _offset = 4;

        if (getType() != _data[1])
            throw new TFTPPacketException("TFTP operator code does not match type.");

        _blockNumber = (((_data[2] & 0xff) << 8) | (_data[3] & 0xff));

        _length = datagram.getLength() - 4;

        if (_length > MAX_DATA_LENGTH)
            _length = MAX_DATA_LENGTH;
    }


> tftp client limited to ~32 MB file sizes
> ----------------------------------------
>
>                 Key: NET-181
>                 URL: https://issues.apache.org/jira/browse/NET-181
>             Project: Commons Net
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Dan Armbrust
>            Priority: Minor
>
> I just noticed that the TFTPClient class does not support a block wraparound - hence, when the block number exceeds the max allowed by the rfc (65535) - about a 32 mb file - bad things will happen.
> I can't find any rfc that specifies how the wraparound is supposed to occur, but this wiki page mentions it:
> http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol
> And I am working on implementing a TFTPServer - and in my tests with the tftp client that is shipped with fedora, I have determined that that tftp client expects the next block number after 65535 to be 0.
> So it appears that the TFTPClient should wrap its block number so that it properly supports larger files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.