Skip to content

Commit

Permalink
don't send corrupted compressed frames.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Dec 16, 2024
1 parent 6d8db78 commit d876b37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
9 changes: 9 additions & 0 deletions src/ZeDMDComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ bool ZeDMDComm::StreamBytes(ZeDMDFrame* pFrame)
size = CTRL_CHARS_HEADER_SIZE + 3 + compressedSize;
pData[CTRL_CHARS_HEADER_SIZE + 1] = (uint8_t)(compressedSize >> 8 & 0xFF);
pData[CTRL_CHARS_HEADER_SIZE + 2] = (uint8_t)(compressedSize & 0xFF);
if ((0 == pData[CTRL_CHARS_HEADER_SIZE + 1] && 0 == pData[CTRL_CHARS_HEADER_SIZE + 2]) ||
// The not compressed RGB565 frame is m_width * m_height * 2, but if every pixel is different, we might be
// bigger.
compressedSize > (m_width * m_height * 3))
{
Log("Compression error");
free(pData);
return false;
}
}

uint8_t flowControlCounter = 255;
Expand Down
14 changes: 0 additions & 14 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,6 @@ void ZEDMDCALLBACK LogCallback(const char* format, va_list args, const void* pUs
printf("%s\n", buffer);
}

uint8_t* CreateImage(int depth)
{
uint8_t* pImage = (uint8_t*)malloc(128 * 32);
int pos = 0;
for (int y = 0; y < 32; ++y)
{
for (int x = 0; x < 128; ++x)
{
pImage[pos++] = x % ((depth == 2) ? 4 : 16);
}
}
return pImage;
}

uint8_t* CreateImageRGB24()
{
uint8_t* pImage = (uint8_t*)malloc(128 * 32 * 3);
Expand Down

0 comments on commit d876b37

Please sign in to comment.