mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Compare commits
2 Commits
dependabot
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38df29380a | ||
|
|
1f438bd40f |
@@ -654,34 +654,15 @@ class DartGenerator : public BaseGenerator {
|
|||||||
|
|
||||||
std::string NamespaceAliasFromUnionType(Namespace* root_namespace,
|
std::string NamespaceAliasFromUnionType(Namespace* root_namespace,
|
||||||
const Type& type) {
|
const Type& type) {
|
||||||
const std::vector<std::string> qualified_name_parts =
|
const Namespace& type_namespace = *type.struct_def->defined_namespace;
|
||||||
type.struct_def->defined_namespace->components;
|
if (root_namespace->components == type_namespace.components) {
|
||||||
if (std::equal(root_namespace->components.begin(),
|
|
||||||
root_namespace->components.end(),
|
|
||||||
qualified_name_parts.begin())) {
|
|
||||||
return namer_.Type(*type.struct_def);
|
return namer_.Type(*type.struct_def);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ns;
|
const std::string ns = namer_.Namespace(type_namespace);
|
||||||
|
return ns.empty()
|
||||||
for (auto it = qualified_name_parts.begin();
|
? namer_.Type(*type.struct_def)
|
||||||
it != qualified_name_parts.end(); ++it) {
|
: ImportAliasName(ns) + "." + namer_.Type(*type.struct_def);
|
||||||
auto& part = *it;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < part.length(); i++) {
|
|
||||||
if (i && !isdigit(part[i]) && part[i] == CharToUpper(part[i])) {
|
|
||||||
ns += "_";
|
|
||||||
ns += CharToLower(part[i]);
|
|
||||||
} else {
|
|
||||||
ns += CharToLower(part[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (it != qualified_name_parts.end() - 1) {
|
|
||||||
ns += "_";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ns + "." + namer_.Type(*type.struct_def);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenImplementationGetters(
|
void GenImplementationGetters(
|
||||||
|
|||||||
@@ -56,8 +56,15 @@ extension Verifiable {
|
|||||||
let len: UOffset = try verifier.getValue(at: position)
|
let len: UOffset = try verifier.getValue(at: position)
|
||||||
let intLen = Int(len)
|
let intLen = Int(len)
|
||||||
let start = Int(clamping: (position &+ MemoryLayout<Int32>.size).magnitude)
|
let start = Int(clamping: (position &+ MemoryLayout<Int32>.size).magnitude)
|
||||||
|
let byteCount = intLen.multipliedReportingOverflow(
|
||||||
|
by: MemoryLayout<T>.size)
|
||||||
|
guard !byteCount.overflow else {
|
||||||
|
throw FlatbuffersErrors.outOfBounds(
|
||||||
|
position: UInt.max,
|
||||||
|
end: verifier.capacity)
|
||||||
|
}
|
||||||
try verifier.isAligned(position: start, type: type.self)
|
try verifier.isAligned(position: start, type: type.self)
|
||||||
try verifier.rangeInBuffer(position: start, size: intLen)
|
try verifier.rangeInBuffer(position: start, size: byteCount.partialValue)
|
||||||
return (start, intLen)
|
return (start, intLen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -411,6 +411,27 @@ final class FlatbuffersVerifierTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(.bug("https://github.com/google/flatbuffers/issues/9082"))
|
||||||
|
func testRejectsTruncatedScalarVector() {
|
||||||
|
// swiftformat:disable all
|
||||||
|
var byteBuffer = ByteBuffer(bytes: [
|
||||||
|
16, 0, 0, 0,
|
||||||
|
6, 0, 8, 0,
|
||||||
|
4, 0, 0, 0,
|
||||||
|
0, 0, 0, 0,
|
||||||
|
12, 0, 0, 0,
|
||||||
|
8, 0, 0, 0,
|
||||||
|
0, 0, 0, 0,
|
||||||
|
2, 0, 0, 0,
|
||||||
|
65, 66,
|
||||||
|
])
|
||||||
|
// swiftformat:enable all
|
||||||
|
|
||||||
|
#expect(throws: FlatbuffersErrors.self) {
|
||||||
|
try getCheckedRoot(byteBuffer: &byteBuffer) as Swift_Tests_Vectors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
func testValidUnionBuffer() {
|
func testValidUnionBuffer() {
|
||||||
let string = "Awesome \\\\t\t\nstring!"
|
let string = "Awesome \\\\t\t\nstring!"
|
||||||
|
|||||||
Reference in New Issue
Block a user