We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3834

Summary: Segfault on call to TTF_OpenFontIndexRW
Product: SDL_ttf Reporter: Dave <davebrda>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sylvain.becker
Version: 2.0.14   
Hardware: x86_64   
OS: Linux   
Attachments: zip file with font is in build folder. physfsrwops is included in this tar. to build: cd build; cmake ..; make

Description Dave 2017-09-19 13:42:35 UTC
Created attachment 2952 [details]
zip file with font is in build folder. physfsrwops is included in this tar. to build: cd build; cmake ..; make

SDL version is 2.0.5-4
SDL_ttf is 2.0.14-1
and PhysFS/physfsrwops is 2.0.3
(on 64 bit linux with g++)

Attached please find short program reproducing the problem and data file. 

The code runs if I comment out the line TTF_Init();.

My debugger says the segfault is happening in TTF_OpenFontIndexRW at line 426 in a call to “main_arena” but I am not finding that function.
Comment 1 Sylvain 2017-09-20 06:33:30 UTC
no familiar with physfs, but this code runs with latest version of SDL2: 

int main(int argc, char* argv[]) {
  SDL_Init(SDL_INIT_EVERYTHING);
  TTF_Init();
  SDL_RWops* rw = SDL_RWFromFile("menlo.ttf", "r");
  if (rw) {
      SDL_Log("ok rw");
  }
  TTF_Font* font = TTF_OpenFontIndexRW(rw, 1, 15, 0); 
  if (font) {
      SDL_Log("ok font");
  }
  return 0;
}

will print

INFO: ok rw
INFO: ok font
Comment 2 Dave 2017-09-20 15:55:37 UTC
I think the problem is with PHYSFSRWOPS_makeRWops because this works fine:

#include <iostream>

#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <physfs.h>

int main(int argc, char* argv[]) {
  SDL_Init(SDL_INIT_EVERYTHING);
  TTF_Init();
  PHYSFS_init(argv[0]);
  PHYSFS_mount("menlo.zip", nullptr, 0);
  PHYSFS_exists("menlo.ttf");
  PHYSFS_File* fp = PHYSFS_openRead("menlo.ttf");
//  SDL_RWops* rw = PHYSFSRWOPS_makeRWops(fp);
  PHYSFS_sint64 file_size = PHYSFS_fileLength(fp);
  char *buf = new char[file_size];
  PHYSFS_read(fp, buf, 1, file_size);
  SDL_RWops* rw = SDL_RWFromMem(buf, file_size);

  TTF_Font* font = TTF_OpenFontIndexRW(rw, 1, 15, 0);
  return 0;
}
Comment 3 Sylvain 2019-10-23 09:13:16 UTC
Marked resolved as Invalid!