Coder Social home page Coder Social logo

Comments (7)

knolleary avatar knolleary commented on May 28, 2024

Hi,

the client library has a maximum packet size of 128 bytes - which your code is exceeding. This isn't a scenario the code guards against (it does for incoming messages, but not for outgoing).

The length value is written to the header and then that number of bytes are copied to the internal payload buffer. If length exceeds the internal buffer, it carries on writing beyond the end of the array, which could cause memory corruption.

I'll put a fix in that guards against this, but in the meantime, if you want to increase the max packet size, change MAX_PACKET_SIZE in PubSubClient.h - this will obviously increase the memory usage of the code.

Nick

from pubsubclient.

DougieLawson avatar DougieLawson commented on May 28, 2024

Thanks Nick. I'll change the length to 140 (you can guess why).

from pubsubclient.

knolleary avatar knolleary commented on May 28, 2024

Actually, looking at it after a cup of tea, the write method only supports a single byte of length - which limits you to a 128 byte message. So you cannot simply change the #define.

When I get a chance later today, I'll put a fix in that enables multi-byte length encoding.

Once that is in place you'll be able to increase the message size.

You'll need to allow for the message headers when determining your message size. The sum is:
1 byte fixed header
2 bytes length (for messages 128 < length <16383 )
2 bytes for the topic length
topic bytes
payload bytes

which gives you 5+topic+payload bytes.

This assumes a qos 0 message (which is all the arduino lib currently supports), otherwise you need another 2 bytes for message ID in there.

from pubsubclient.

DougieLawson avatar DougieLawson commented on May 28, 2024

I've found that forked copy of your library. I'll take a look at that.

from pubsubclient.

knolleary avatar knolleary commented on May 28, 2024

Which forked copy? I haven't kept track of the handful of forks others have done, but I'm not aware of anyone making these changes already.

from pubsubclient.

DougieLawson avatar DougieLawson commented on May 28, 2024

https://github.com/karlp/pubsubclient

Or I'll put my S/370 (aka zSeries now) Assembler knowledge back in the cupboard, sharpen my C/C++ coding pencil and hack at your code.

I've been doing messaging and queuing for 30 years (along with lots of DL/I and DB2 databases), This MQTT stuff is like a little IMS thing. It's lots of fun. Look me up in BluePages.

from pubsubclient.

knolleary avatar knolleary commented on May 28, 2024

Reviewing the open issues. The library now handles larger packets (when the MAX packet size constant is changed in the .h file). Nothing more to do here.

from pubsubclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.