#189 Eval does not save filename in permanent buffer

Internals (76)

In script.cpp (Revision
Line Code
265 DynamicCharBuffer buf(size+1);
266 if (!ReadFile(h, buf, size, &size, NULL))
267 env->ThrowError("Import: unable to read \"%s\"", script_name);
268 CloseHandle(h);
270 ((char*)buf)[size] = 0;
271 AVSValue eval_args[] = { (char*)buf, script_name };
272 result = env->Invoke("Eval", AVSValue(eval_args, 2));
the buf local variable is not saved with env->SaveString (as it should for the reason explained below) before invoking 'Eval'.

In class ExpLine in expression.h (Revision the constructor just stores the value of the pointer and not the data (assuming the char buffer will be valid for the lifetime of the class).
Line Code
145 ExpLine(const PExpression& _exp, const char* _filename, int _line)
146 : ExpExceptionTranslator(_exp), filename(_filename), line(_line) {}

The implicit assumption done at the constructor would be true only if Expline objects would not persist beyond the end of the Import Call.

However all script functions entered in the global function table during this Import call will persist the Import call and thus they will contain 'filename' pointers to invalid memory.

This shows up only when en error condition occurs in the actual script function's call -later in the script after the Import returns or inside a runtime filter- at the moment when the ExpLine::Evaluate member function calls env->ThrowError with the invalid 'filename' pointer (expression.cpp, Revision
Line Code
253 catch (AvisynthError ae) {
254 env->ThrowError("%s\n(%s, line %d)", ae.msg, filename, line);

Thus any error in a script function's logic results in exceptions that will be caught by other higher-level handlers and of course they are misleading for the true cause of the error.


  • Ian Brabham

    Ian Brabham - 2008-04-14
    • assigned_to: nobody --> ianb1957
    • summary: Import does not save filename in permanent buffer --> Eval does not save filename in permanent buffer
    • status: open --> closed-fixed
  • Ian Brabham

    Ian Brabham - 2008-04-14

    Logged In: YES
    Originator: NO

    gzarkadas, Nice job, thanks. I implemented the fix 1 level down, inside Eval.

    See avisynth/src/core/parser/script.cpp version 1.22
    < ScriptParser parser(env, args[0].AsString(), args[1].AsString(0));
    > char *filename = args[1].AsString(0);
    > if (filename) filename = env->SaveString(filename);
    > ScriptParser parser(env, args[0].AsString(), filename);



Log in to post a comment.