Skip to content

Commit

Permalink
superblock: eliminate UB during binary magnitude extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
div72 committed Mar 5, 2024
1 parent 7cd0247 commit 6e92287
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/gridcoin/superblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,9 @@ class LegacySuperblockParser

for (size_t x = 0; x < binary_size && binary_size - x >= 18; x += 18) {
magnitudes.AddLegacy(
*reinterpret_cast<const Cpid*>(byte_ptr + x),
be16toh(*reinterpret_cast<const int16_t*>(byte_ptr + x + 16)));
Cpid(std::vector<unsigned char>(byte_ptr + x, byte_ptr + x + 16)),
(((uint16_t)byte_ptr[x + 16] & 0xFF) << 8) | ((uint16_t)byte_ptr[x + 17] & 0xFF)
);
}

return magnitudes;
Expand Down
2 changes: 1 addition & 1 deletion src/test/gridcoin/superblock_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Legacy
struct BinaryResearcher
{
std::array<unsigned char, 16> cpid;
int16_t magnitude;
uint16_t magnitude;
};

static std::string ExtractValue(std::string data, std::string delimiter, int pos)
Expand Down

0 comments on commit 6e92287

Please sign in to comment.