-
Notifications
You must be signed in to change notification settings - Fork 120
EtcTool crash #10
Comments
Can you provide your input argument that causes the crash in ptrOutputDir ? |
For what it's worth, I'm encountering the same bug when running etctool under Ubuntu Precise. It's a memory error, so reproducing it in any given environment is probably going to be difficult. But in my specific case, I've observed the failure as a tripped malloc() assert for certain output path formats. For example, this output path containing a directory name of exactly 23 characters reproduces the crash for me, while directories of other lengths (tried 4-36) do not:
A gdb stacktrace shows the failure occurs in lodepng_realloc() at third_party/lodepng/lodepng.cpp:73, although I'm pretty sure there's nothing wrong with lodepng.cpp -- it's just fallout from the buffer overrun in EtcTool.cpp. The corruption is reliably detected by valgrind for any input:
Per @spearx 's suggestion, I am able to fix both the valgrind output and the malloc assertion by expanding the buffer by one to accommodate the null terminator, on the following line: https://github.com/google/etc2comp/blob/e2e733c/EtcTool/EtcTool.cpp#L654 |
I agree with @spearx and @jclee, it looks like an off-by-one error. The allocated size of the buffer is of size Either Edit: test case is to have an output file with a slash (dir separator) in it |
* fix from google#10
Hi guys, sometimes i have a crash in the EtcTool.
I reviewed the code and i found a char array with a bad size.
In the EtcTool.cpp in function ProcessCommandLineArguments
if (pstrOutputFilename[c] == ETC_PATH_SLASH) { c++; ptrOutputDir = new char[c]; strncpy(ptrOutputDir, pstrOutputFilename, c); ptrOutputDir[c] = '\0'; CreateNewDir(ptrOutputDir); break; }
The ptrOutputDir variable has a bad size, the must be c+1, i changed my code to:
if (pstrOutputFilename[c] == ETC_PATH_SLASH) { c++; ptrOutputDir = new char[c+1]; strncpy(ptrOutputDir, pstrOutputFilename, c); ptrOutputDir[c] = '\0'; CreateNewDir(ptrOutputDir); break; }
And now all run right.
Thanks,
Ruben
The text was updated successfully, but these errors were encountered: