-
Notifications
You must be signed in to change notification settings - Fork 247
Description
The issue was discovered by Coverity scan that we do at intel/llvm repo, you can view the scan and request access here: https://scan.coverity.com/projects/intel-llvm?tab=overview
CID 546125:
SPIRV-LLVM-Translator/lib/SPIRV/SPIRVReader.cpp
Lines 5696 to 5705 in 35827fe
| if (!BM->getFnVarSpvOut().empty()) { | |
| auto SaveOpt = SPIRVUseTextFormat; | |
| auto OFSSpv = std::ofstream(BM->getFnVarSpvOut(), std::ios::binary); | |
| SPIRVUseTextFormat = false; | |
| OFSSpv << *BM; | |
| if (BM->getError(ErrMsg) != SPIRVEC_Success) { | |
| return false; | |
| } | |
| SPIRVUseTextFormat = SaveOpt; | |
| } |
SPIRVUseTextFormat value is not restored to its original value in case of errors.
Whilst I don't know if there is a practical use case for this, this is technically a problem, because readSpirv is part of the public translator API:
SPIRV-LLVM-Translator/include/LLVMSPIRVLib.h
Lines 160 to 163 in 35827fe
| /// \brief Load SPIR-V from istream and translate to LLVM module. | |
| /// \returns true if succeeds. | |
| bool readSpirv(LLVMContext &C, const SPIRV::TranslatorOpts &Opts, | |
| std::istream &IS, Module *&M, std::string &ErrMsg); |
As such, there could exist an application which calls it multiple times where some invocations may produce unexpected results