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

fix(freetype): fix using memfs to create a FT font #5627

Merged
merged 2 commits into from
Feb 12, 2024

Conversation

hpfaz
Copy link
Contributor

@hpfaz hpfaz commented Feb 8, 2024

Description of the feature or fix

lv_freetype_req_face_id drops path metadata when using memfs,
fix uses drive letter to adjust malloc/memcpy length when creating
the cache node.

To reproduce:

in lv_conf.h : #define LV_FREETYPE_USE_LVGL_PORT 1, #define LV_USE_FREETYPE 1, LV_USE_FS_MEMFS 1
snippet:

lv_fs_path_ex_t font_path = {0};
lv_fs_make_path_from_buffer(&font_path,
    LV_FS_MEMFS_LETTER,
    buffer_p,
    buffer_sz);
lv_font_t *font_p =
    lv_freetype_font_create(
        (char const*)&font_path,
        LV_FREETYPE_FONT_RENDER_MODE_BITMAP,
        font_sz,
        LV_FREETYPE_FONT_STYLE_NORMAL);

Result:

Program will most likely crash due to OOB memory accesses when trying to use path metadata.

Notes

lv_freetype_req_face_id drops path metadata when using memfs

Signed-off-by: Hatim-Pierre FAZILEABASSE <hatim-pierre.fazileabasse@ingenico.com>
Copy link
Contributor

@C47D C47D left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Please run the code-format.py in the scripts directory and then commit the formated file.

LV_ASSERT_MALLOC(node->pathname);
strcpy(node->pathname, pathname);
memcpy(node->pathname, pathname, len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PGNetHun ,

Actually this can't be used here because when you use memfs the path is actually a pointer to a lv_fs_path_ex_t object. The first field of this structure is a null terminated string.
When cast to char * subsequent use of strlen will only copy the first field of the structure thus leading to the loss of the relevant metadata for proper use of memfs.
I hope that clears out why I used this hack on len and malloc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense.

@PGNetHun
Copy link
Collaborator

PGNetHun commented Feb 9, 2024

please fix C code formatting issue

Signed-off-by: Hatim-Pierre FAZILEABASSE <hatim-pierre.fazileabasse@ingenico.com>
@hpfaz hpfaz requested a review from PGNetHun February 9, 2024 12:50
LV_ASSERT_MALLOC(node->pathname);
strcpy(node->pathname, pathname);
memcpy(node->pathname, pathname, len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense.

Copy link
Collaborator

@XuNeo XuNeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@XuNeo XuNeo merged commit 06812c7 into lvgl:master Feb 12, 2024
16 checks passed
@hpfaz hpfaz deleted the bugfix/freetype_memfs_support branch February 23, 2024 10:30
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 this pull request may close these issues.

None yet

4 participants