-
Notifications
You must be signed in to change notification settings - Fork 464
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
Crash in sass_compile_file from uninitialised Context.importer #662
Comments
The crash in There's a |
From your code I guess you are mixing old and new API? On your remarks on IMO calloc is not needed as all the allocated memory is overwritten properly in that function. |
I'm only using the The Visual C++ 2013 debugging runtime enables a lot of consistency checks in The C standard defines |
Here's my test program that crashes in #include <stdio.h>
#include "libsass/sass_interface.h"
int main()
{
sass_file_context *ctx = sass_new_file_context();
ctx->input_path = "test.scss";
int status = sass_compile_file(ctx);
if (ctx->error_status == 0) {
puts(ctx->output_string);
} else {
puts(ctx->error_message);
}
sass_free_file_context(ctx);
return 0;
} |
When I compile this on linux I get:
Is this still an issue with latest master? |
Sorry, that code looks for the SCSS file I was using for testing. The minimum needed to reproduce the problem is a file
|
Works for me!? test.scss:
inc.scss
|
I can't reproduce it with GCC on Linux, since the stack is initialised to zeros there, so the pointers in
I've been able to fix the crash in Windows by either initialising all fields in --- a/context.hpp
+++ b/context.hpp
@@ -83,6 +83,8 @@ namespace Sass {
bool _skip_source_map_update; // status flag to skip source map updates
KWD_ARG_SET(Data) {
+ public:
+ Data() : source_c_str_(), include_paths_c_str_(), include_paths_array_(), importer_() {}
KWD_ARG(Data, const char*, source_c_str);
KWD_ARG(Data, string, entry_point);
KWD_ARG(Data, string, input_path); or by explicitly setting --- a/sass_interface.cpp
+++ b/sass_interface.cpp
@@ -209,6 +209,7 @@ extern "C" {
.include_paths_array(0)
.include_paths(vector<string>())
.precision(c_ctx->options.precision ? c_ctx->options.precision : 5)
+ .importer(0)
);
if (c_ctx->c_functions) {
struct Sass_C_Function_Descriptor** this_func_data = c_ctx->c_functions; I prefer the former, since that way both POD and non-POD fields of the |
Thanks for digging into the issue 👍 I will have a look and add your fix. |
Perhaps this VS issue is related: sass/node-sass#530 (comment) :) |
There's no reason not to make both changes. The mythical perfect optimising compiler would generate the same code for either or both. @am11 The first commit in a94377b should fix the crash in |
@carey, thanks for looking into it. I have been wandering around the code to find more improvement and I ran Code Analysis on it, it gives some interesting pointers about memory related issues. Here is the log: http://pastebin.com/qgTgz7nS. I have fixed couple of them, but for example this: a471673#commitcomment-8652376, I couldn't figure out. The interesting thing is, it draws the entire path to memory corruptions/leaks. There are total of 26 or warnings Code Analysis throws. It might be worth fixing (unlike .NET projects, it takes quite sometime to test all code paths, at least on i7 Lenovo). |
Thanks for the fix in 375b769. There's very similar code in After that fix too, and realising that |
I have found that node-sass importer callback is invoked till 21688e1. As soon as I checkout to next commit e0a5d03, it stops calling the cb. Another regression is described here 8957ad8#commitcomment-8644934. |
I've been working on my own integration of LibSass with Java on Windows, but with my last pull of libsass it's started crashing at:
Initialising importer to 0 lets sass_compile_file run successfully. (It crashes later in sass_free_file_context when free() detects a buffer overflow.)
The text was updated successfully, but these errors were encountered: