Fixing FilerSWIs
Fred Graute (114) 645 posts |
Some time ago Martin Bazley reported a bug in Transient. After some digging around it turned out that the cause was FilerSWIs and how it was being used. The SWI FilerAction_SendSelectedFile is used to add a new file. FilerSWIs collects the filenames thus sent until it has received sufficient filenames to fill a message block. The message FilerAddSelection is then sent to FilerAction so that it can add the filenames to the list of files to act upon. The name FilerAction_SendSelectedFile suggests that it expects a single filename each time but the implementation is such that it will accept a null-terminated list of space-separated filenames. This is mentioned in the example in the WIMP StrongHelp manual, and this is how I was using it. As the list of filenames is passed in a buffer allocated by the client application it can be any size, unfortunately FilerSWIs assumes that it won’t exceed 235 bytes. When the SWI is called it first checks if the new data can be added to the data already collected without overrunning the buffer. If that’s not possible it sends the message and purges the buffer. Next it copies the new data to the buffer without checking its length, overrunning its RMA based buffer when there’s too much data. This can lead to all kinds of errors depending on what’s being overwritten in the RMA (for me it crashed the WIMP each time). The question is how to fix this; should we fault any data that’s over 235 bytes long, or should we keep filling the buffer and sending the message until all data is processed? Personally I prefer the second solution as it’s more efficient (only one SWI call instead of many) and the StrongHelp manual which suggests this usage is already out there. The downside is that the SWI name is then slightly inaccurate. The SWI FilerAction_SendSelectedDirectory has a couple of issues as well; it too doesn’t check the length of the data passed in, and it allows spaces in the directory name. Any thoughts? |