Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceCompiler crashes on address-sanitized builds. #301

Closed
ycwn opened this issue Sep 13, 2018 · 2 comments · Fixed by #537
Closed

ResourceCompiler crashes on address-sanitized builds. #301

ycwn opened this issue Sep 13, 2018 · 2 comments · Fixed by #537

Comments

@ycwn
Copy link

ycwn commented Sep 13, 2018

Hi guys!

I have ran into an issue with the ResourceCompiler on address-sanitized builds.
It crashes when trying to access the JSON maniffest in an archive (in validateManifestInArchive()).
The call to mz_zip_reader_extract_file_to_heap() does not include a null terminator for the string in
its allocated buffer, although the memory beyond seems zeroed-out. In address-sanitized builds
this space is guarded, causing the program to abort during construction of the istringstream a few
lines below.

I have included a patch that fixes this issue.

diff --git a/tools/rc/ResourceCompiler.cpp b/tools/rc/ResourceCompiler.cpp
index ef15376..d2fecdc 100644
--- a/tools/rc/ResourceCompiler.cpp
+++ b/tools/rc/ResourceCompiler.cpp
@@ -179,8 +179,9 @@ void validateManifestInArchive(mz_zip_archive* zipArchive,
                                const std::string& archiveFile,
                                const std::string& archiveEntry)
 {
+  size_t length = 0;
   void* data = mz_zip_reader_extract_file_to_heap(
-    zipArchive, archiveEntry.c_str(), nullptr, 0);
+    zipArchive, archiveEntry.c_str(), &length, 0);
   std::unique_ptr<void, void (*)(void*)> manifestFileContents(data, ::free);
 
   if (!manifestFileContents) {
@@ -191,7 +192,7 @@ void validateManifestInArchive(mz_zip_archive* zipArchive,
   try {
     Json::Value root;
     std::istringstream json(
-      reinterpret_cast<const char*>(manifestFileContents.get()));
+      std::string(reinterpret_cast<const char*>(manifestFileContents.get()), length));
     parseAndValidateJson(json, root);
   } catch (const InvalidManifest& e) {
     std::string exceptionMsg(archiveFile);
@ksubramz
Copy link
Contributor

Thanks a lot for the report and patch! We'll review and merge it.

@ycwn
Copy link
Author

ycwn commented Sep 14, 2018

perfect, thank you!

jeffdiclemente pushed a commit that referenced this issue Mar 26, 2021
* Made changes to ResourceCompiler.cpp to remove ASAN and TSAN errors
* Removed tsan_suppressions.txt from the repo

Signed-off-by: The MathWorks, Inc. <alchrist@mathworks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants