[GH-ISSUE #1157] --input-encoding problem #722

Closed
opened 2026-10-14 03:21:23 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @loverszhaokai on GitHub (Mar 26, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1157

#1. Compare the two cases

Both Case 1 and Case 2 are invalid.

1.1 Case 1

$ ./john 7z_fmt --input-encoding=11

Invalid encoding. Supported encodings:
ASCII, UTF-8, ISO-8859-1 (or latin1), ISO-8859-2, ISO-8859-7, ISO-8859-15, KOI8-R,
CP437, CP720, CP737, CP850, CP852, CP858, CP866, CP868,
CP1250, CP1251, CP1252, CP1253, CP1254, CP1255, CP1256

1.2 Case 2

$ ./john 7z_fmt --input-encoding=11111111111111111111111111111111111

Loaded 1 password hash (7z, 7-Zip [SHA256 AES 32/64])
Will run 8 OpenMP threads
Note: This format may emit false positives, so it will keep trying even after
finding a possible candidate.
Press 'q' or Ctrl-C to abort, almost any other key for status
password (?)
#2. Debug

I think john should report error message and exit in Case 2.

2.1 unicode::cp_name2id()

Location: unicode.c int cp_name2id(char *encoding)

 int cp_name2id(char *encoding)
 {
         char enc[16] = "";
         char *d = enc;

         if (!encoding || strlen(encoding) > sizeof(enc))
                return CP_UNDEF;
         ...

         if (!strcmp(enc, "raw") || !strcmp(enc, "ascii"))
               return ASCII;
         else

         fprintf(stderr, "Invalid encoding. Supported encodings:\n");
         listEncodings(stderr);
         exit(EXIT_FAILURE);
}

16 == sizeof(enc), so the cp_name2id() will return CP_UNDEF for long encoding in Case 2.
Why not print error message?

Originally created by @loverszhaokai on GitHub (Mar 26, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1157 #1. Compare the two cases Both Case 1 and Case 2 are invalid. ## 1.1 Case 1 $ ./john 7z_fmt --input-encoding=11 **Invalid encoding**. Supported encodings: ASCII, UTF-8, ISO-8859-1 (or latin1), ISO-8859-2, ISO-8859-7, ISO-8859-15, KOI8-R, CP437, CP720, CP737, CP850, CP852, CP858, CP866, CP868, CP1250, CP1251, CP1252, CP1253, CP1254, CP1255, CP1256 ## 1.2 Case 2 $ ./john 7z_fmt --input-encoding=11111111111111111111111111111111111 Loaded 1 password hash (7z, 7-Zip [SHA256 AES 32/64]) Will run 8 OpenMP threads Note: This format may emit false positives, so it will keep trying even after finding a possible candidate. Press 'q' or Ctrl-C to abort, almost any other key for status password (?) #2. Debug I think john should **report error message** and **exit** in Case 2. ## 2.1 unicode::cp_name2id() Location: unicode.c int cp_name2id(char *encoding) ``` C int cp_name2id(char *encoding) { char enc[16] = ""; char *d = enc; if (!encoding || strlen(encoding) > sizeof(enc)) return CP_UNDEF; ... if (!strcmp(enc, "raw") || !strcmp(enc, "ascii")) return ASCII; else fprintf(stderr, "Invalid encoding. Supported encodings:\n"); listEncodings(stderr); exit(EXIT_FAILURE); } ``` 16 == sizeof(enc), so the cp_name2id() will return **CP_UNDEF** for **long encoding** in Case 2. Why not print error message?
bsakaguchi 2026-10-14 03:21:23 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@magnumripper commented on GitHub (Mar 26, 2015):

That is a good question... Does "git blame" shed some light on it?

<!-- gh-comment-id:86489874 --> @magnumripper commented on GitHub (Mar 26, 2015): That is a good question... Does "git blame" shed some light on it?
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper

github.com/magnumripper/JohnTheRipper@e19a0c7cf3

This commit add the function: cp_name2id.

<!-- gh-comment-id:86493633 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper https://github.com/magnumripper/JohnTheRipper/commit/e19a0c7cf3c312c4a306fc9864c26265c025ef30 This commit add the function: cp_name2id.
Author
Owner

@magnumripper commented on GitHub (Mar 26, 2015):

Yeah, we should probably bail out the same way as we do in case 1.

<!-- gh-comment-id:86497219 --> @magnumripper commented on GitHub (Mar 26, 2015): Yeah, we should probably bail out the same way as we do in case 1.
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper OK, I will fix this bug and test again. Thanks.

<!-- gh-comment-id:86498487 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper OK, I will fix this bug and test again. Thanks.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#722
No description provided.