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

librecode can hang for invalid conversions #52

Open
bkmgit opened this issue Oct 18, 2023 · 2 comments
Open

librecode can hang for invalid conversions #52

bkmgit opened this issue Oct 18, 2023 · 2 comments

Comments

@bkmgit
Copy link

bkmgit commented Oct 18, 2023

When testing AnyMeal, on Fedora 38, found
that the program below

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <recodext.h>

const char *program_name;

int
main (int argc, char *const *argv)
{
  program_name = argv[0];
  RECODE_OUTER outer = recode_new_outer (true);
  RECODE_REQUEST request = recode_new_request (outer);
  char input_buffer[10] = "Äpfel";
  char *output_buffer;
  size_t output_length;
  size_t input_length = 6;
  size_t output_allocated;
  bool success;

  success = recode_scan_request (request, "latin1..ascii");
  request->verbose_flag = true;
  RECODE_TASK task = recode_new_task(request);
  task->input.buffer = input_buffer;
  task->input.cursor = input_buffer;
  task->input.limit = input_buffer + input_length;
  task->output.buffer = output_buffer;
  task->output.cursor = output_buffer;
  task->output.limit = output_buffer + output_allocated;
  printf("Starting task\n");
  success = recode_perform_task (task);
  printf("Task complete\n");
  output_buffer = task->output.buffer;
  output_length = task->output.cursor - task->output.buffer;
  output_allocated = task->output.limit - task->output.buffer;
  recode_delete_task (task);
  printf("%s\n",output_buffer);
  recode_delete_request (request);
  recode_delete_outer (outer);

  exit (success ? 0 : 1);
}

hangs and does not print Task Complete. If one changes Äpfel to Apfel it works. Attempting the conversion from the command line does however issue an error message that the input is untranslatable. This is with release 3.7.14

@bkmgit
Copy link
Author

bkmgit commented Oct 18, 2023

The following works correctly:

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <recodext.h>

const char *program_name;

int main (int argc, char *const *argv)
{
  program_name = argv[0];
  RECODE_OUTER outer = recode_new_outer (true);
  RECODE_REQUEST request = recode_new_request (outer);
  request->verbose_flag = true;
  char input_buffer[10] = "Äpfel";
  char *output_buffer;
  size_t output_length;
  size_t input_length = 6;
  size_t output_allocated = 20;
  output_buffer = (char*)malloc(output_allocated * sizeof(char));
  bool success;

  success = recode_scan_request (request, "latin1..ascii");
  RECODE_TASK task = recode_new_task(request);
  task->fail_level = RECODE_NOT_CANONICAL;
  task->abort_level = RECODE_NOT_CANONICAL;
  task->input.buffer = input_buffer;
  task->input.cursor = input_buffer;
  task->input.limit = input_buffer + input_length;
  task->output.buffer = output_buffer;
  task->output.cursor = output_buffer;
  task->output.limit = output_buffer + output_allocated;
  printf("Starting task\n");
  success = recode_perform_task (task);
  printf("Task complete\n");
  output_buffer = task->output.buffer;
  output_length = task->output.cursor - task->output.buffer;
  output_allocated = task->output.limit - task->output.buffer;
  recode_delete_task (task);

  if (success) printf("%s\n",output_buffer);
  free(output_buffer);
  recode_delete_request (request);
  recode_delete_outer (outer);

  exit (success ? 0 : 1);
}

@rrthomas
Copy link
Owner

Thanks for this. I'm sorry, but my time to work on Recode is limited at present, and librecode is not a high priority. If you can provide any further analysis, I'd be most grateful; otherwise, I'll look at it when I can!

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

No branches or pull requests

2 participants