Skip to content

Commit

Permalink
Protect against an invalid JSON batch table.
Browse files Browse the repository at this point in the history
Unfortunately, rapidjson doesn't really have a valid empty document object.
  • Loading branch information
timoore committed Feb 2, 2023
1 parent a0959d1 commit 6fbffd2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 52 deletions.
104 changes: 53 additions & 51 deletions Cesium3DTilesSelection/src/BatchTableToGltfFeatureMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,61 +1408,63 @@ void convertBatchTableToGltfFeatureMetadataExtension(
featureTable.count = featureCount;
featureTable.classProperty = "default";

// Convert each regular property in the batch table
for (auto propertyIt = batchTableJson.MemberBegin();
propertyIt != batchTableJson.MemberEnd();
++propertyIt) {
std::string name = propertyIt->name.GetString();

// Don't interpret extensions or extras as a property.
if (name == "extensions" || name == "extras") {
continue;
}
if (batchTableJson.IsObject()) {
// Convert each regular property in the batch table
for (auto propertyIt = batchTableJson.MemberBegin();
propertyIt != batchTableJson.MemberEnd();
++propertyIt) {
std::string name = propertyIt->name.GetString();

ClassProperty& classProperty =
classDefinition.properties.emplace(name, ClassProperty()).first->second;
classProperty.name = name;
// Don't interpret extensions or extras as a property.
if (name == "extensions" || name == "extras") {
continue;
}

FeatureTableProperty& featureTableProperty =
featureTable.properties.emplace(name, FeatureTableProperty())
.first->second;
const rapidjson::Value& propertyValue = propertyIt->value;
if (propertyValue.IsArray()) {
updateExtensionWithJsonProperty(
gltf,
classProperty,
featureTable,
featureTableProperty,
ArrayOfPropertyValues(propertyValue));
} else {
BinaryProperty& binaryProperty = binaryProperties.emplace_back();
updateExtensionWithBinaryProperty(
gltf,
gltfBufferIndex,
gltfBufferOffset,
binaryProperty,
classProperty,
featureTableProperty,
result,
featureTable,
name,
propertyValue);
gltfBufferOffset += roundUp(binaryProperty.byteLength, 8);
ClassProperty& classProperty =
classDefinition.properties.emplace(name, ClassProperty()).first->second;
classProperty.name = name;

FeatureTableProperty& featureTableProperty =
featureTable.properties.emplace(name, FeatureTableProperty())
.first->second;
const rapidjson::Value& propertyValue = propertyIt->value;
if (propertyValue.IsArray()) {
updateExtensionWithJsonProperty(
gltf,
classProperty,
featureTable,
featureTableProperty,
ArrayOfPropertyValues(propertyValue));
} else {
BinaryProperty& binaryProperty = binaryProperties.emplace_back();
updateExtensionWithBinaryProperty(
gltf,
gltfBufferIndex,
gltfBufferOffset,
binaryProperty,
classProperty,
featureTableProperty,
result,
featureTable,
name,
propertyValue);
gltfBufferOffset += roundUp(binaryProperty.byteLength, 8);
}
}
}

// Convert 3DTILES_batch_table_hierarchy
auto extensionsIt = batchTableJson.FindMember("extensions");
if (extensionsIt != batchTableJson.MemberEnd()) {
auto bthIt =
extensionsIt->value.FindMember("3DTILES_batch_table_hierarchy");
if (bthIt != extensionsIt->value.MemberEnd()) {
updateExtensionWithBatchTableHierarchy(
gltf,
classDefinition,
featureTable,
result,
bthIt->value);
// Convert 3DTILES_batch_table_hierarchy
auto extensionsIt = batchTableJson.FindMember("extensions");
if (extensionsIt != batchTableJson.MemberEnd()) {
auto bthIt =
extensionsIt->value.FindMember("3DTILES_batch_table_hierarchy");
if (bthIt != extensionsIt->value.MemberEnd()) {
updateExtensionWithBatchTableHierarchy(
gltf,
classDefinition,
featureTable,
result,
bthIt->value);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Cesium3DTilesSelection/src/PntsToGltfConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ void convertPntsContentToGltf(

createGltfFromParsedContent(parsedContent, result);

if (batchTableJson.HasParseError() || batchTableJson.MemberCount() == 0 ||
if (batchTableJson.HasParseError() ||
parsedContent.dracoMetadataHasErrors) {
result.errors.merge(parsedContent.errors);
return;
Expand Down

0 comments on commit 6fbffd2

Please sign in to comment.