Page MenuHomePhabricator

elm_image_file_set segfaults when path is NULL
Closed, ResolvedPublic

Description

<ajwillia_ms> kuuko: pretty sure the api should never segfault :)

What he said.

Bakctrace:

#0  __strlen_sse2_bsf () at ../sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S:50
No locals.
#1  0xb716cd17 in _efl_ui_image_is_remote (file=0x0)
    at lib/elementary/efl_ui_image.c:1085
        itr = <optimized out>
#2  _efl_ui_image_efl_file_file_set (obj=0x400027fe, sd=0x87b4f80, file=0x0, 
    key=0x0) at lib/elementary/efl_ui_image.c:1116
        ret = 0 '\000'
#3  0xb663f10c in efl_file_set (obj=0x400027fe, file=0x0, key=0x0)
    at ../src/lib/efl/interfaces/efl_file.eo.c:3
        _r = <optimized out>
        ___cache = {index = {{klass = 0x8778a38}}, entry = {{
              func = 0x875a6e8}}, off = {{off = 552}}, op = 985, 
          generation = 1}
        ___call = {eo_id = 0x400027fe, obj = 0x87b4d58, 
          func = 0xb716cc80 <_efl_ui_image_efl_file_file_set>, 
          data = 0x87b4f80, extn1 = 0x669, extn2 = 0xb701467c <_mutex_big>, 
          extn3 = 0xb6cffa79, extn4 = 0xb6cffcf0 <__FUNCTION__.14771>}
        _func_ = <optimized out>
#4  0xb716d7bb in elm_image_file_set (obj=0x400027fe, file=0x0, group=0x0)
    at lib/elementary/efl_ui_image.c:1966
        ret = 0 '\000'

Example code here:
https://github.com/rbtylee/Elementary/tree/master/test

#include <Elementary.h>

EAPI_MAIN int
elm_main(int argc, char **argv)
{
   Evas_Object *win = NULL, *image = NULL, *btn = NULL, *bx = NULL;
   char buf[PATH_MAX];
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
   win = elm_win_util_standard_add("test", "Hello Elementary");
   elm_win_autodel_set(win, EINA_TRUE);
   
   bx = elm_box_add(win);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas_object_show(bx);
   
   snprintf(buf, sizeof(buf), "bodhilogo-simple.png");

   image = elm_image_add(win);
    /*if (!elm_image_file_set(image, buf, NULL))
     {
        printf("error: could not load image \"%s\"\n", buf);
        return -1;
     } */
   elm_image_file_set(image, NULL, NULL);
   evas_object_size_hint_weight_set(image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, image);
   evas_object_show(image);
   
   evas_object_resize(win, 300, 200);
   evas_object_show(win);

   elm_run(); 
   return EXIT_SUCCESS;
}
ELM_MAIN()

//Compile with:
//gcc -o elm_image elm_image.c -g `pkg-config --cflags --libs elementary`
kuuko created this task.Jul 9 2017, 3:25 PM
kuuko updated the task description. (Show Details)Jul 9 2017, 3:33 PM

if img does not have prev loaded image then on file_set(.., NULL, ..) it will just ignore this API call and returns FALSE.
if img has prev loaded img then on file_set(.., NULL, ..) it will delete the previous img and returns TRUE;

jpeg added a comment.Jul 9 2017, 11:38 PM

if img does not have prev loaded image then on file_set(.., NULL, ..) it will just ignore this API call and returns FALSE.
if img has prev loaded img then on file_set(.., NULL, ..) it will delete the previous img and returns TRUE;

And in both cases we end up with a "blank image", right?

In T5697#90922, @jpeg wrote:

if img does not have prev loaded image then on file_set(.., NULL, ..) it will just ignore this API call and returns FALSE.
if img has prev loaded img then on file_set(.., NULL, ..) it will delete the previous img and returns TRUE;

And in both cases we end up with a "blank image", right?

Yup

kuuko added a comment.Jul 10 2017, 4:49 PM

I suggest you also write a test case for this.

jpeg added a comment.Jul 10 2017, 7:24 PM
In T5697#91197, @kuuko wrote:

I suggest you also write a test case for this.

Very good point. That could go into make check, not necessarily elm test.