Bug #3636

nml fails validating escapes at end of string

Added by Eddi almost 6 years ago. Updated over 5 years ago.

Status:ClosedStart date:2012-02-03
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:-
Target version:-

Description

CETS r607 fails with the following error:

@>>> main.main(['--nfo','cets.nfo','cets.nml'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "../nml/nml/main.py", line 151, in main
ret = nml(input, input_filename, opts.debug, outputs, opts.sprites_dir, opts.start_sprite_num, opts.forced_palette)
File "../nml/nml/main.py", line 213, in nml
lang_actions.extend(action4.get_global_string_actions())
File "../nml/nml/actions/action4.py", line 100, in get_global_string_actions
texts.append( (0x7F, (string_range << 8) | id, grfstrings.get_translation(string_name), feature) )
File "../nml/nml/grfstrings.py", line 127, in get_translation
return default_lang.get_string(string)
File "../nml/nml/grfstrings.py", line 671, in get_string
str_type = self.strings[string_id].get_type()
File "../nml/nml/grfstrings.py", line 487, in get_type
if not is_ascii_string(comp): return 'unicode'
File "../nml/nml/grfstrings.py", line 59, in is_ascii_string
if string[i+1] in ('\\', 'n', '"'):
IndexError: string index out of range

import pdb
pdb.pm()

/home/johannes/.openttd/dbs/nml/nml/grfstrings.py(59)is_ascii_string()

-> if string[i+1] in ('\\', 'n', '"'):
(Pdb) l
54 if string[i] != '\\':
55 if ord(string[i]) >= 0x7B:
56 return False
57 i += 1
58 else:
59 -> if string[i+1] in ('\\', 'n', '"'):
60 i += 2
61 elif string[i+1] == 'U':
62 return False
63 else:
64 i += 3
(Pdb) p string
u"(1A)(A1)+2'2'\\"
(Pdb) p i
13
(Pdb) p string13
u'\\'@

Associated revisions

Revision 1907:18ba8d81fce5
Added by Hirundo over 5 years ago

Fix #3636: Backslash-escapes in strings weren't properly validated. Also remove useless \n escape.

Revision 2020:4e47a5702b21
Added by Hirundo over 5 years ago

Fix #3636: Backslash-escapes in strings weren't properly validated. Also remove useless \n escape.

Revision 1907:18ba8d81fce5
Added by Hirundo over 5 years ago

Fix #3636: Backslash-escapes in strings weren't properly validated. Also remove useless \n escape.

Revision 2020:4e47a5702b21
Added by Hirundo over 5 years ago

Fix #3636: Backslash-escapes in strings weren't properly validated. Also remove useless \n escape.

History

#1 Updated by Eddi almost 6 years ago

sorry, this report is totally ill-formatted. but getting a preview fails for me somehow...

#2 Updated by Hirundo almost 6 years ago

The error triggers in get_string_size, but fixing it there would be the wrong thing, methinks.
Escapes should be parsed and checked during string loading, or at some separate validation stage.

Also, I noticed \n is treated as a valid escape. Is this needed/wanted, considering that we have {} to insert a newline? Does it even work, as OpenTTD uses 0D (\r) for newline?

#3 Updated by yexo almost 6 years ago

If I read the code in output_grf.py correctly, using \n will put a literal n in the output instead of a newline. Since it doesn't work, it hasn't been used and we might as well remove it.

#4 Updated by Hirundo over 5 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset 18ba8d81fce5.

Also available in: Atom PDF