Problems with BMP files and security questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee Marsh

    Problems with BMP files and security questions

    First questions was already posted over on a.php, but no one responded, so
    I'm gonna post it again here:

    So I have a block of code that is used when a user uploades a picture file.
    Initially the script detects what kind of picture file the user uploaded and
    then acts accordingly. The following is the code for a jpeg:

    if($t == 'image/jpeg'){

    $src_img = ImagecreateFrom Jpeg($uploadfil e);
    $size = getimagesize(". ./album/users/$uname/$album/$pic_name");
    $width = $size[0];
    $height = $size[1];

    $width = round(($width/4));
    $height = round(($height/4));
    $dst_img = ImageCreateTrue Color($width,$h eight);

    ImageCopyResize d($dst_img, $src_img, 0,0,0,0, $width, $height, $size[0],
    $size[1]);

    ImageJpeg($dst_ img, "users/$uname/$album/small/$pic_name", 60);


    Basically, makes a picture is the appropriate folder, then resizes makes a
    copy 1/4th the size before in another folder. Now, I can pretty much reuse
    this code with gifs and pngs, by just changing the relevant functions, but
    here's my question: with bmp files, it wont seem to work at all. It gives an
    error message that basically says that the bmp file the user uploades isnt a
    valid bmp file. Any idea how to get that to work?


    The second question I have is in regards to security and PHP. I'm basically
    making my first web application that other people might actually use, so I
    have to make sure it's secure. So far, what I plan on doing is making sure
    that data from users is not left blank, doesn't exceed the expected length,
    and whenever possible is completely alphanumeric. With the file uploads, I'm
    checking for file type as well. Is there anything else that I should keep in
    mind? Also, I'm not really that good at regular expressions yet, so if
    someone could tell me if some of the reg. exps. I'm using are adequate would
    be good.
    To check for a valid email:
    ^[a-zA-z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$
    and
    to check that data is alphanumeric: [^0-9a-zA-z]

    Thanks a lot in advance.


    --
    <============ =>
    --Lee


    Goodbye, adios, bis bald, see ya later, weidersehen, and everything in
    between


  • Alvaro G. Vicario

    #2
    Re: Problems with BMP files and security questions

    *** Lee Marsh escribió/wrote (Tue, 25 Jan 2005 04:05:49 GMT):[color=blue]
    > here's my question: with bmp files, it wont seem to work at all. It gives an
    > error message that basically says that the bmp file the user uploades isnt a
    > valid bmp file. Any idea how to get that to work?[/color]

    Just find out what MIME type is set when you upload a BMP file.


    --
    -+ Álvaro G. Vicario - Burgos, Spain
    +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
    ++ Manda tus dudas al grupo, no a mi buzón
    -+ Send your questions to the group, not to my mailbox
    --

    Comment

    • Lee Marsh

      #3
      Re: Problems with BMP files and security questions

      See, thats the easy part though. There's different functions for handeling
      bmp's as there is for handeling jpeg's, but it doesn't seem like i can get
      any of the ones that might work for bmps to work right and i have no idea
      why.

      --
      <============ =>
      --Lee


      Goodbye, adios, bis bald, see ya later, weidersehen, and everything in
      between
      "Alvaro G. Vicario" <kAlvaroNOSPAMT HANKS@terra.es> wrote in message
      news:1bqlmw2q83 7bn$.6p47ck0jac 3x.dlg@40tude.n et...[color=blue]
      > *** Lee Marsh escribió/wrote (Tue, 25 Jan 2005 04:05:49 GMT):[color=green]
      >> here's my question: with bmp files, it wont seem to work at all. It gives
      >> an
      >> error message that basically says that the bmp file the user uploades
      >> isnt a
      >> valid bmp file. Any idea how to get that to work?[/color]
      >
      > Just find out what MIME type is set when you upload a BMP file.
      >
      >
      > --
      > -+ Álvaro G. Vicario - Burgos, Spain
      > +- http://www.demogracia.com (la web de humor barnizada para la
      > intemperie)
      > ++ Manda tus dudas al grupo, no a mi buzón
      > -+ Send your questions to the group, not to my mailbox
      > --[/color]


      Comment

      • kicken

        #4
        Re: Problems with BMP files and security questions

        Lee Marsh wrote:[color=blue]
        > See, thats the easy part though. There's different functions for handeling
        > bmp's as there is for handeling jpeg's, but it doesn't seem like i can get
        > any of the ones that might work for bmps to work right and i have no idea
        > why.
        >[/color]

        The problem you're encountering probably is simply a mis-understanding
        of the functions. The ImageCreateFrom WBMP is not for bitmap images, at
        least not the way you are thinking. If you look at the first user
        comment, you will see:

        <quote>
        WBMP images are Wireless Bitmaps, not Windows Bitmaps. WBMP is used for
        bandwidth constrained, black and white, limited devices such as PDAs and
        Cell Phones.
        </quote>

        So, normal bitmaps, like you create in MS Paint, are not valid for these
        functions. To be honest, I'm not sure if there are any functions for
        these images.

        Comment

        • Alvaro G. Vicario

          #5
          Re: Problems with BMP files and security questions

          *** Lee Marsh escribió/wrote (Wed, 26 Jan 2005 03:04:33 GMT):[color=blue]
          > See, thats the easy part though. There's different functions for handeling
          > bmp's as there is for handeling jpeg's, but it doesn't seem like i can get
          > any of the ones that might work for bmps to work right and i have no idea
          > why.[/color]

          My excuses, I didn't actually read your complete post, I was scared by the
          code <:-) I just read 'upload' and 'detect' and...

          The manual says about image functions:

          "It can also be used to create and manipulate image files in a variety of
          different image formats, including gif, png, jpg, wbmp, and xpm."

          Some of the functions work with BMP files (e.g. getimagesize) but most of
          them don't. If it's a Unix server you probably have ImageMagick installed.
          This packege includes very useful commands to handle most graphic formats
          and can be invoked via exec().


          --
          -+ Álvaro G. Vicario - Burgos, Spain
          +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
          ++ Manda tus dudas al grupo, no a mi buzón
          -+ Send your questions to the group, not to my mailbox
          --

          Comment

          • Lee Marsh

            #6
            Re: Problems with BMP files and security questions

            Gotcha. So I guess my site won't be able to support BMP files. Just out of
            curiosity, any idea why PHP doesn't support BMP files in that sense?

            PS
            I guess I'll have so post my second question again in another group since
            it's buried now...

            --
            <============ =>
            --Lee

            Goodbye, adios, bis bald, see ya later, weidersehen, and everything in
            between
            "Alvaro G. Vicario" <kAlvaroNOSPAMT HANKS@terra.es> wrote in message
            news:1jx6p8twsk 4w1$.17k91rwf9a fu6$.dlg@40tude .net...[color=blue]
            > *** Lee Marsh escribió/wrote (Wed, 26 Jan 2005 03:04:33 GMT):[color=green]
            >> See, thats the easy part though. There's different functions for
            >> handeling
            >> bmp's as there is for handeling jpeg's, but it doesn't seem like i can
            >> get
            >> any of the ones that might work for bmps to work right and i have no idea
            >> why.[/color]
            >
            > My excuses, I didn't actually read your complete post, I was scared by the
            > code <:-) I just read 'upload' and 'detect' and...
            >
            > The manual says about image functions:
            >
            > "It can also be used to create and manipulate image files in a variety of
            > different image formats, including gif, png, jpg, wbmp, and xpm."
            >
            > Some of the functions work with BMP files (e.g. getimagesize) but most of
            > them don't. If it's a Unix server you probably have ImageMagick installed.
            > This packege includes very useful commands to handle most graphic formats
            > and can be invoked via exec().
            >
            >
            > --
            > -+ Álvaro G. Vicario - Burgos, Spain
            > +- http://www.demogracia.com (la web de humor barnizada para la
            > intemperie)
            > ++ Manda tus dudas al grupo, no a mi buzón
            > -+ Send your questions to the group, not to my mailbox
            > --[/color]


            Comment

            • Alvaro G. Vicario

              #7
              Re: Problems with BMP files and security questions

              *** Lee Marsh escribió/wrote (Wed, 26 Jan 2005 15:16:28 GMT):[color=blue]
              > Gotcha. So I guess my site won't be able to support BMP files. Just out of
              > curiosity, any idea why PHP doesn't support BMP files in that sense?[/color]

              I guess they have little use in web sites.


              --
              -+ Álvaro G. Vicario - Burgos, Spain
              +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
              ++ Manda tus dudas al grupo, no a mi buzón
              -+ Send your questions to the group, not to my mailbox
              --

              Comment

              Working...