Repository navigation
Hardening: add null guards, bounds checks, and file saver safety to language IDL generators - #9371
Open
anagnorisis2peripeteia wants to merge 1 commit into
Conversation
…anguage IDL generators
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR strengthens defensive engineering across FlatBuffers language IDL generators (Swift, TypeScript, Rust, Python, Java, Kotlin, C#, Dart, PHP, Lobster, Text, and gRPC):
src/idl_gen_swift.cpp:parser_.opts.file_saveragainstnullptrbefore invokingSaveFile.parser_.enums_.vecandparser_.structs_.vecloops before dereferencing**it.src/idl_gen_ts.cpp:definition.defined_namespaceagainstnullptrinSaveType.parser_.opts.file_saveragainstnullptr.TrackNsDefchild namespace re-export loops, guardit.second.nsandit2.second.nsagainst null and verify!it2.second.ns->components.empty()before iterator subtraction (end() - count).src/idl_gen_rust.cpp:parser.opts.file_saveragainstnullptrinGenerateRustModuleRootFile.symbol.defined_namespaceandparser_.opts.file_saveragainst null inGenerateIndividualFiles.parser_.opts.file_saveragainst null inGenerateSingleFile.src/idl_gen_python.cpp:parser_.opts.file_saverinPythonStubGenerator::SaveFileandPythonGenerator::SaveType.PythonGenerator::SaveType, verifypath_.size() <= directories.size()before callingstd::string::findto prevent out-of-bounds indexing.parser_.opts.file_saverwhen creating empty__init__.pyfiles.src/idl_gen_java.cpp:parser_.opts.file_saveragainstnullptrinJavaGenerator::SaveType.src/idl_gen_kotlin.cpp&src/idl_gen_kotlin_kmp.cpp:parser_.opts.file_saveragainstnullptrinKotlinGenerator::SaveTypeandKotlinKmpGenerator::SaveType.src/idl_gen_csharp.cpp:options.file_saveragainstnullptrinCSharpGenerator::SaveType.src/idl_gen_dart.cpp:parser_.opts.file_saveragainstnullptrbefore invokingSaveFile.src/idl_gen_php.cpp:def.defined_namespaceandparser_.opts.file_saveragainst null inPhpGenerator::SaveType.src/idl_gen_lobster.cpp:*itin structs loop against null.parser_.opts.file_saveragainst null inLobsterGenerator::generate.src/idl_gen_text.cpp:parser.opts.file_saveragainst null inGenTextFileflexbuffers and normal text paths.src/idl_gen_grpc.cpp:defanddef->defined_namespaceinGoGRPCGeneratorandJavaGRPCGenerator.*itagainst null inparser.services_.veciteration acrossGenerateGoGRPC,GenerateCppGRPC,GenerateJavaGRPC,GeneratePythonGRPC,GenerateSwiftGRPC.parser.opts.file_saveragainst null across C++, Java, Swift, and TypeScript gRPC generators.tests/test.cpp:IdlLanguageGeneratorsSafetyTest()verifying thatGenerateTextFilefails cleanly and returnsSaveFile failedwhenopts.file_saver == nullptr.All tests compile cleanly under
-DFLATBUFFERS_STRICT_MODE=ONand pass withflattestsandflatc_cpp_tests.py.