-
Notifications
You must be signed in to change notification settings - Fork 271
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
[BUG] Even with the "--restrict" option, some file names do not cause an error when imported. #1585
Comments
I think you may misunderstand this option. First of all, I don't know where do you read the documentation? Is it for Pyarmor 8. Could you list the reference link? |
Sorry. I modified it too much to make it simple. Of course, I had read the documentation and understood that the restrict option was for package only, but I didn't think that individual files in a package should not be specifiled for encryption, and since it appeared to me that there was no change in behavior, I misunderstood. File Structureroot a.pyimport p.t as t
t.f() t.pyNo change Reproduction procedures
Expect an error in steps 3, but no error in fact |
@jondy |
I have revised the content to make it a bit clearer. Also, after rechecking, it seems that not only --restrict, but also --private causes similar problems. Reproduction proceduresFile Structureroot a.pytry:
import p.s as s
s.a()
except Exception as e:
print(e)
try:
import p.t as t
t.a()
except Exception as e:
print(e) s.py and t.pydef a():
print("protected")
Expected result
Actual result
Trace Log (pyarmor.trace.log)
|
Can't reproduced, it raises 2 exceptions in my test, please make sure no local configuration to change something |
Thank you very much. We will examine the situation closely. |
Deleting the pyarmor configuration had no effect. It was reproduced in the environment immediately after installing pyarmor for the first time. I don't know why it doesn't reproduce in your environment at this time, but I fixed it so that the reproduction procedure can be performed automatically. Reproduction proceduresa.pyimport string
import os
import subprocess
func = """
def a():
print("protected")
"""
os.makedirs(r"p", exist_ok=True)
for s in string.ascii_lowercase:
with open(rf"p\{s}.py", "w") as f:
f.write(func)
subprocess.run("python -m venv .venv")
subprocess.run(".venv\scripts\python -m pip install pyarmor==8.4.4")
subprocess.run(".venv\scripts\pyarmor gen --restrict p")
with open(rf"dist\main.py", "w") as f:
for s in string.ascii_lowercase:
func = f"""
try:
import p.{s}
p.{s}.a()
except Exception as e:
print(f"{s}.py: {{e}}")
else:
print(f"{s}.py: could be accessed")
"""
f.write(func)
subprocess.run(r".venv\scripts\python dist\main.py")
Expected result
Actual result
|
I have tried multiple environments, Windows 10, 11, and linux(Ubuntu), and it occurs in all of them. We would like to closely examine the conditions under which the problem occurs, so can you please provide us with information on your environments in which the problem does not reproduce itself? |
Make sure you're using Pyarmor 8.4.6 |
Confirmed with the latest version.
|
Reproduced, I'll check it. |
It will be fixed in next release, or apply this patch for quick workaround --- a/pyarmor/cli/context.py
+++ b/pyarmor/cli/context.py
@@ -466,7 +466,7 @@ class Context(object):
@property
def exclude_restrict_modules(self):
- return self._opts('builder', 'exclude_restrict_modules')
+ return self._opts('builder', 'exclude_restrict_modules').split() |
Thanks for the quick fix. |
Depending on the file name, neither import, function call, nor direct invocation of the file may result in an error.
Environment
Reproduction procedures
a.py
t.py
t.py is one of the error-free filenames. There are many other error-free filenames.
If the filename is s.py, then an error will occur on import. However, changing the file name after encryption does not change the result. The name must not be t.py before encryption.
Expect an error in steps 3 and 4, but no error in fact
Trace Log (pyarmor.trace.log)
The text was updated successfully, but these errors were encountered: