Bug - Fixed r17705 - Cannot use map_to_file() to save into subfolders in /data

guyy

Member
As the title says, map_to_file() will not save to a subfolder in /data using any syntax I can think of. Instead, it saves to the main data folder, whether the specified subfolder already exists or not.

map_to_file(array,"subfolder/filename.txt") -> saves to "/data/filename.txt" instead of "/data/subfolder/filename.txt". This definitely used to work, one of my old scripts uses it extensively (though luckily this bug doesn't affect it for people who only Mafia with one account).

file_to_map("subfolder/filename.txt",array) -> successfully loads from the subfolder. But it still can't save to the subfolder.

Not sure if I'm just being dumb, or this is intentional, but it seems buggy.

Example, for completeness:

Code:
void main()
{
	string[string] testarray;
	testarray["test"] = random(1000);
	map_to_file(testarray,"testfolder/testfile.txt");
}
 

lostcalpolydude

Developer
Staff member
There was a time when you could use map_to_file() to save to anywhere on the computer, rather than just in KoLmafia's folder. I made some changes to prevent that (a few years ago, at this point), and I wouldn't be too surprised if that led to this not working...
 

ckb

Minion
Staff member
Does this also follow for file_to_map()?
It would be beneficial to be able to open data files from other locations too.
 

lostcalpolydude

Developer
Staff member
It turns out I had thrown a few markers in that file a long time ago to look at later...

17706 allows writing to subfolders of /data. It's also probably better at preventing arbitrary directory traversal, in case there's some way to do that without using /.

You can also access files in /scripts, /relay, and mafia's root directory (the last one surprises me), as long as they aren't .ash and they already exist.

Does this also follow for file_to_map()?
Yes.

And as I typed this, 17707 prevents you from accessing arbitrary subdirectories of mafia's root directory.
 

ckb

Minion
Staff member
Yes.

And as I typed this, 17707 prevents you from accessing arbitrary subdirectories of mafia's root directory.

Now I remember why I was looking into this. I wanted to see what my moods were in an ash script, so I was trying to access /settings/player_name()_moods.txt. This does not work for the reasons you stated above. I filed a feature request. and I coded a workaround in the meantime.
 

lostcalpolydude

Developer
Staff member
The settings folder was the main reason for 17707, making sure that GLOBAL_prefs.txt stayed inaccessible with hashed passwords stored in it.
 

heeheehee

Developer
Staff member
The settings folder was the main reason for 17707, making sure that GLOBAL_prefs.txt stayed inaccessible with hashed passwords stored in it.

Nit: they're not hashed, so much encoded as a base-36 integer (IIRC; my script that reverses saveStates agrees with me). Hash implies an irreversible computation that provides a signature, of sorts, that can be used as a proxy for the original string without storing the actual text (for various reasons, e.g. security or storage space).
 
Top