[MPlayer-dev-eng] Re: [PATCH] fix for issue cant play filenames with spaces

adland adland123 at yahoo.com
Fri Apr 30 04:09:09 CEST 2004


I was reading the spec mentioned in the url.c file to find out more about this.

http://www.ietf.org/rfc/rfc2396.txt

problem is mentioned in this text

Because the percent "%" character always has the reserved purpose of
being the escape indicator, it must be escaped as "%25" in order to
be used as data within a URI.

Note: we dont want to use % as data when it is part of an escape sequence.

Implementers should be careful not to
escape or unescape the same string more than once, since unescaping
an already unescaped string might lead to misinterpreting a percent
data character as another escaped character, or vice versa in the
case of escaping an already escaped string.

Note: this is restriction is violated in current code for this http test case
 and causes  a problem as Compn stated earlier.
 my change only tries to fix problems with multiple string escapes on same
 string.
 
valid escape strings

      escaped     = "%" hex hex
      hex         = digit | "A" | "B" | "C" | "D" | "E" | "F" |
                            "a" | "b" | "c" | "d" | "e" | "f"

Issues found in our unescape_url function
 1- our unescape function is broken as it doenst handle lowercase a-f
 2- also could read past end of string when % is at end without
    being part of a valid escape sequence. examples text% or text%a

and my change (patch) to url escape function is also broken for Issue 1.

a fixed url_unescape function which I tested directly is below:

void
url_unescape_string(char *outbuf, const char *inbuf)
{
 unsigned char c,c1,c2;
 int i;
 int len=strlen(inbuf);

  for (i=0;i<len;i++)
  {
   c=inbuf[i];
   if (c == '%' && i<len-2) { //must have two more chars
   c1=toupper(inbuf[i+1]); // need next 2 chars as uppercase
   c2=toupper(inbuf[i+2]);
   if (    ((c1>='0' && c1<='9') || (c1>='A' && c1<='F')) && 
           ((c2>='0' && c2<='9') || (c2>='A' && c2<='F')) ) {
          if (c1>='0' && c1<='9') c1-='0';
          else c1-='A'-10;
          if (c2>='0' && c2<='9') c2-='0';
          else c2-='A'-10;
          c = (c1<<4) + c2;
          i=i+2; // only skip next c1 & c2  chars if it was valid esc
      }
   }
   *outbuf++=c;
  }
  *outbuf++='\0'; // add nullterm to string

}

//test function
int main(int argc,char **argv) {
 if (argc !=2) {
         printf("Usage: %s <arg>\n",argv[0]);
         return 1;
     }
 char out[strlen(argv[1])+1]; //space for output
                             //unescaped same size or less

 printf("Input: %s\n",argv[1]);
 url_unescape_string(out,argv[1]);
 printf ("New string is %s\n",out);
 return 0;
}

please comment
thanks




More information about the MPlayer-dev-eng mailing list