Closed ramonpoca closed 8 years ago
Are you sure it's not the second assertion? I.e. assert(sizeof(usbmux_packet_t) == 16);
I'm working on a new version of peertalk where I fixed an issue pertaining to this, namely that depending on compiler version and settings, the actual size of a struct might be larger than what's needed (usually an optimization to align it to words.) This might cause sizeof
to report not the logical size, but the effective size of the struct.
Can you repro the crash? If so, run the app through lldb (e.g. lldb /path/to/your.app/Contents/MacOS/your
) and see where it actually aborts from an assertion. It's also possible you've got a stack overflow issue in which case the stack trace might be incorrect.
BTW, the fix to the struct size is this:
typedef struct usbmux_packet {
...
} __attribute__((__packed__)) usbmux_packet_t;
The second assert should crash on the first call, as sizeof(usbmux_packet_t)
is known at compile time (and might be even optimized out). We are getting the traces through Crashlytics, and the issue repeats quite frequently.
I tried to replicate the call sequence to check for any unexpected value of payloadLength
causing the crash, but couldn't. But note that nowhere is checked that the received upacket_len
is bigger than sizeof(usbmux_packet_t)
, so a corrupt/unexpected packet of zero or less than 16 size would cause payloadLength
to have a value near to UINT32_MAX
(adding back 16 in usbmux_packet_alloc
will cause this to allocate undersized packets).
b3090d72e56b8714e6ce7d7658038e3a77c4b38f makes some changes that should help in preventing getting into these situations. usbmux_packet
s are only used during negotiation with the USB mux hub, but isn't used for user communication (i.e. PTChannel doesn't use these packets and doesn't have these limitations.)
We're getting crash dumps from our OS X app pointing to an assertion being triggered in PTUSBHub.m line 66:
We poll the USB port repeatedly waiting for a device with our client app to connect. The crazy thing about that is the assert being triggered should be:
but the stack shows this coming from the
dispatch_io_read
inscheduleReadPacketWithCallback
(PTUSBHub.m:494), which uses auint32_t
parameter, thus making it (theoretically) impossible to overflowUINT32_MAX
:Any ideas? Maybe stack corruption in the previous
memcpy
(should be protected by the assertion, so...)?