mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-15 20:20:58 +02:00
more guards to corrupt voxel files
This commit is contained in:
parent
a189f077b8
commit
5ec98b8dec
4 changed files with 47 additions and 4 deletions
|
@ -246,6 +246,13 @@ int Octree::readElementData(OctreeElement* destinationElement, const unsigned ch
|
|||
return bytesAvailable; // assume we read the entire buffer...
|
||||
}
|
||||
|
||||
if (destinationElement->getScale() < SMALLEST_REASONABLE_OCTREE_ELEMENT_SCALE) {
|
||||
qDebug() << "UNEXPECTED: readElementData() destination element is unreasonably small ["
|
||||
<< destinationElement->getScale() * (float)TREE_SCALE << " meters] "
|
||||
<< " Discarding " << bytesAvailable << " remaining bytes.";
|
||||
return bytesAvailable; // assume we read the entire buffer...
|
||||
}
|
||||
|
||||
unsigned char colorInPacketMask = *nodeData;
|
||||
bytesRead += sizeof(colorInPacketMask);
|
||||
bytesLeftToRead -= sizeof(colorInPacketMask);
|
||||
|
@ -366,7 +373,12 @@ void Octree::readBitstreamToTree(const unsigned char * bitstream, unsigned long
|
|||
OctreeElement* bitstreamRootElement = nodeForOctalCode(args.destinationElement, (unsigned char *)bitstreamAt, NULL);
|
||||
|
||||
int numberOfThreeBitSectionsInStream = numberOfThreeBitSectionsInCode(bitstreamAt, bufferSizeBytes);
|
||||
int octalCodeBytesInStream = bytesRequiredForCodeLength(numberOfThreeBitSectionsInStream);
|
||||
|
||||
if (numberOfThreeBitSectionsInStream == OVERFLOWED_OCTCODE_BUFFER) {
|
||||
qDebug() << "UNEXPECTED: parsing of the octal code would overflow the buffer. This buffer is corrupt. Returning.";
|
||||
return;
|
||||
}
|
||||
|
||||
int numberOfThreeBitSectionsFromNode = numberOfThreeBitSectionsInCode(bitstreamRootElement->getOctalCode());
|
||||
|
||||
if (numberOfThreeBitSectionsInStream != numberOfThreeBitSectionsFromNode) {
|
||||
|
@ -384,7 +396,7 @@ void Octree::readBitstreamToTree(const unsigned char * bitstream, unsigned long
|
|||
}
|
||||
}
|
||||
|
||||
int octalCodeBytes = octalCodeBytesInStream;
|
||||
int octalCodeBytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInStream);
|
||||
|
||||
int theseBytesRead = 0;
|
||||
theseBytesRead += octalCodeBytes;
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QDebug>
|
||||
#include <QImage>
|
||||
#include <QRgb>
|
||||
|
||||
|
||||
#include "VoxelTree.h"
|
||||
#include "Tags.h"
|
||||
|
||||
|
@ -567,3 +566,26 @@ int VoxelTree::processEditPacketData(PacketType packetType, const unsigned char*
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class VoxelTreeDebugOperator : public RecurseOctreeOperator {
|
||||
public:
|
||||
virtual bool preRecursion(OctreeElement* element);
|
||||
virtual bool postRecursion(OctreeElement* element) { return true; }
|
||||
};
|
||||
|
||||
bool VoxelTreeDebugOperator::preRecursion(OctreeElement* element) {
|
||||
VoxelTreeElement* treeElement = static_cast<VoxelTreeElement*>(element);
|
||||
qDebug() << "VoxelTreeElement [" << treeElement << ":" << treeElement->getAACube() << "]";
|
||||
qDebug() << " isLeaf:" << treeElement->isLeaf();
|
||||
qDebug() << " color:" << treeElement->getColor()[0] << ", "
|
||||
<< treeElement->getColor()[1] << ", "
|
||||
<< treeElement->getColor()[2];
|
||||
return true;
|
||||
}
|
||||
|
||||
void VoxelTree::dumpTree() {
|
||||
// First, look for the existing entity in the tree..
|
||||
VoxelTreeDebugOperator theOperator;
|
||||
recurseTreeWithOperator(&theOperator);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ public:
|
|||
const unsigned char* editData, int maxLength, const SharedNodePointer& node);
|
||||
virtual bool recurseChildrenWithData() const { return false; }
|
||||
|
||||
virtual void dumpTree();
|
||||
|
||||
private:
|
||||
// helper functions for nudgeSubTree
|
||||
void recurseNodeForNudge(VoxelTreeElement* element, RecurseOctreeOperation operation, void* extraData);
|
||||
|
|
|
@ -73,6 +73,13 @@ OctreeElement::AppendState VoxelTreeElement::appendElementData(OctreePacketData*
|
|||
int VoxelTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
|
||||
ReadBitstreamToTreeParams& args) {
|
||||
const int BYTES_PER_COLOR = 3;
|
||||
|
||||
if (bytesLeftToRead < BYTES_PER_COLOR) {
|
||||
qDebug() << "UNEXPECTED: readElementDataFromBuffer() only had " << bytesLeftToRead << " bytes. "
|
||||
"Not enough for meaningful data.";
|
||||
return bytesLeftToRead;
|
||||
}
|
||||
|
||||
|
||||
// pull the color for this child
|
||||
nodeColor newColor = { 128, 128, 128, 1};
|
||||
|
|
Loading…
Reference in a new issue