Skip to content

Comments

Fix crash when read the config file#952

Merged
lotem merged 1 commit intoBYVoid:masterfrom
epico:fix-crash
Mar 26, 2025
Merged

Fix crash when read the config file#952
lotem merged 1 commit intoBYVoid:masterfrom
epico:fix-crash

Conversation

@epico
Copy link
Contributor

@epico epico commented Mar 25, 2025

No description provided.

@epico
Copy link
Contributor Author

epico commented Mar 25, 2025

We got some bug report in the bugzilla.

URL: https://bugzilla.redhat.com/show_bug.cgi?id=2354375

@HinTak
Copy link

HinTak commented Mar 25, 2025

I think a better answer is to read config from /usr/share/opencc (or equivalent), and only read from current directory if prefixed with "./" or "/" full path. I just wasn't expecting the "-c" argument to be interpreted relative to current. The input / output for sure look at the current directory, but the config files are supposedly fixed look-up tables, and I was not expecting opencc to read it from current directory first.

@HinTak
Copy link

HinTak commented Mar 25, 2025

I encountered the bug because I was making a new directory "s2t" for the converted output; and occasionally I run "opencc -c s2t ..." in its patent, unknowingly. Sometimes I run the command in a different directory, but often I create a sub-directory "s2t" for converted outputs, before filing them elsewhere.

@lotem
Copy link
Collaborator

lotem commented Mar 26, 2025

I encountered the bug because I was making a new directory "s2t" for the converted output; and occasionally I run "opencc -c s2t ..." in its patent, unknowingly. Sometimes I run the command in a different directory, but often I create a sub-directory "s2t" for converted outputs, before filing them elsewhere.

It sounds like an edge case. Not many people happen to have a local directory with the same basename.

Changing the path finding logic isn't necessary to fix the crash and it won't be easy either since some downstream projects may be relying on the current behaviour. It deserves opening a separate issue if you want to continue the discussion.

@lotem
Copy link
Collaborator

lotem commented Mar 26, 2025

@epico Thanks for the fix.
Feel free to merge the PR when it is ready.

@HinTak
Copy link

HinTak commented Mar 26, 2025

I agree the current behavior, looking for config in currrent directory, is probably used by some, more likely than mine (having an unrelated sub-dir which collides). But it would be nice to see how "-c config-arg" is processed in the help page, for example. I just assumed that it would be expanded to finding "/usr/share/opencc/config-arg.json" . For example, does it look for ./config-arg.json too? Or other additional extensions?

@lotem
Copy link
Collaborator

lotem commented Mar 26, 2025

I agree the current behavior, looking for config in currrent directory, is probably used by some, more likely than mine (having an unrelated sub-dir which collides). But it would be nice to see how "-c config-arg" is processed in the help page, for example. I just assumed that it would be expanded to finding "/usr/share/opencc/config-arg.json" . For example, does it look for ./config-arg.json too? Or other additional extensions?

it looks for the json file in the current working directory first, then in PACKAGE_DATA_DIRECTORY which is the default data install path. Giving the current working directory top-priority is the convention for path finding. It allows "overriding" a default configuration file with the user modified copy.

@epico
Copy link
Contributor Author

epico commented Mar 26, 2025

Thanks for the review!

@lotem Sorry, I think I don't have the permission to merge this pull request.

@lotem lotem merged commit cfe3ced into BYVoid:master Mar 26, 2025
24 of 25 checks passed
@HinTak
Copy link

HinTak commented Mar 26, 2025

But it looks for "config-arg" without extension as a json?

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.

3 participants