WTF Bites


  • 🚽 Regular

    @boomzilla said in WTF Bites:

    @Gąska I an boomzilla and :kneeling_warthog:

    Too lazy to even finish the second leg of the m.



  • @Gąska said in WTF Bites:

    @jinpa said in WTF Bites:

    @Gąska said in WTF Bites:

    @jinpa defeats 99.99999% of spambots, and with only 2-3 registrations per year doesn't put too much workload on the admin. I think it's quite genius!

    There are some here who might think that sending passwords in plaintext is not the best practice, but as long as you don't re-use passwords (which you shouldn't be doing anyway), then the risk is fairly low.

    The best practices usually denote a way higher standard than actually practical (see: all the overengineered singleton patterns that have functionality equivalent to a simple global variable).

    For an attacker to be able to intercept the password, they need to:

    • Know that the password is being sent to that email in the first place.
    • Intercept the email somehow, which requires knowing not just the destination, but also the source and the time of transmission. Or an always-on listener, which would be a bold strategy, Cotton.
    • Decrypt the email because even though at application layer it's plaintext, at transport layer it's encrypted.

    I can see how a person registering on PCLinuxOS-Forums might be worried about this happening to them.

    @error_bot xkcd security

    also: you can just change your password once you're logged in



  • @ben_lubar said in WTF Bites:

    also: you can just change your password once you're logged in

    And as long as there's a work-around for the user, no one can say you did things the wrong way.



  • @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    
    • If you've got invalid base-64, you've got to fix it before passing it to the decoder. That's fully expected. Most decoders reject strings that are not properly padded at the end.
    • If C# had Euclidean modulo, the correct expression would be just (-datastring.Length) % 4, but it does not, so you'd have to write it as either ((-datastring.Length) % 4 + 4) % 4 or (4 - datastring.Length % 4) % 4.
    • Getting the base-64 strings without their padding is the :wtf: here.

  • Notification Spam Recipient

    @Bulb said in WTF Bites:

    • Getting the base-64 strings without their padding is the :wtf: here.

    I blame PHP.



  • @boomzilla said in WTF Bites:

    @Gąska I an boomzilla and :kneeling_warthog:

    If the Romans came after you, how many would say they were Boomzilla then?



  • @Tsaukpaetra said in WTF Bites:

    I blame PHP.

    That's always a safe choice.



  • @hungrier Metroid Prime 2 is one of my favorite games.



  • @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?


  • Notification Spam Recipient

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.


  • Notification Spam Recipient

    Status: Trying to help someone deal with an application that does not work well in resolutions smaller than 1280x768. Apparently his Mac is doing weird shit, or he really does have a pre-OMG-my-pixels-are-so-numerous-than-yours-eye-can-handlez! screen.

    Edit: Anyone know how to get Safari more-fuller-screen-like?

    d06f2eaa-6a4c-4d72-9500-5486cd31c7b8-image.png

    I don't Mac much and this poor guy can't seem to do it (either with the green-circle method or the View-Fullscreen method).


  • Discourse touched me in a no-no place

    @Tsaukpaetra Is that RDP inside Safari? Why not just use the proper Remote Desktop client?



  • @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2


  • 🚽 Regular

    @ben_lubar said in WTF Bites:

    is there a single situation where % 4 % 2 is different than just % 2?

    :technically-correct: NaN


  • Discourse touched me in a no-no place

    @Tsaukpaetra said in WTF Bites:

    Edit: Anyone know how to get Safari more-fuller-screen-like?

    d06f2eaa-6a4c-4d72-9500-5486cd31c7b8-image.png

    I don't Mac much and this poor guy can't seem to do it (either with the green-circle method or the View-Fullscreen method).

    The standard green button window control is the way to do it, and works with all Safari windows that I tested it with. (View→Full Screen does the same thing. Or Control (^)+Command (⌘)+F, which is the keyboard shortcut for it.) That would leave you with just a few things at the top of the screen that could mostly be hidden (especially if only one tab is in use) but otherwise be generally acceptable; only the main browser control bar seems to be mandatory (plus a menubar that shows up when the mouse is pushed to the top of the screen). These mechanisms are also all pretty much the same in Chrome, but that lets you hide slightly more when the mouse pointer isn't at the very top so that the user sees just the page. I can see the arguments for the ways both browsers work…

    If your user can't handle the standard mechanisms, there's really not much we can do.

    Technically, the above mode is treated by modern Macs as effectively a separate virtual desktop, so you can (by default, unless disabled in settings) use a three-finger left/right swipe to move between them (or three-finger swipe up to get a screen where you can select which desktop to show, among other things).


  • Java Dev

    @Bulb said in WTF Bites:

    Getting the base-64 strings without their padding is the :wtf: here.

    I've seen it often enough. But then we're in the C world, so naturally we have our own homegrown base64 decoder, which does not mind unpadded base64.


  • Notification Spam Recipient

    @loopback0 said in WTF Bites:

    @Tsaukpaetra Is that RDP inside Safari? Why not just use the proper Remote Desktop client?

    Because it's not straight-up RDP but an HTML websocket thing that the proper client has no idea how to talk to?


  • Notification Spam Recipient

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?



  • @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    And I'm guessing x % 3 (which would return exactly one of 0 1 2 wouldn't work because...


  • Discourse touched me in a no-no place

    @Tsaukpaetra said in WTF Bites:

    Because it's not straight-up RDP but an HTML websocket thing that the proper client has no idea how to talk to?

    That's special.


  • Notification Spam Recipient

    @Benjamin-Hall said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    And I'm guessing x % 3 (which would return exactly one of 0 1 2 wouldn't work because...

    Because then it wouldn't be aligning to four characters?

    I would have just stuck with %4 but apparently you can't have more than two == in a row with base64. Or something.


  • Notification Spam Recipient

    @loopback0 said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Because it's not straight-up RDP but an HTML websocket thing that the proper client has no idea how to talk to?

    That's special.

    It's Guacamole. 🤷♀



  • @Tsaukpaetra said in WTF Bites:

    @Benjamin-Hall said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    And I'm guessing x % 3 (which would return exactly one of 0 1 2 wouldn't work because...

    Because then it wouldn't be aligning to four characters?

    I would have just stuck with %4 but apparently you can't have more than two == in a row with base64. Or something.

    Ah. I missed the whole set of requirements and focused just on the numbers. That's...special.


  • Notification Spam Recipient

    @Benjamin-Hall said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @Benjamin-Hall said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    And I'm guessing x % 3 (which would return exactly one of 0 1 2 wouldn't work because...

    Because then it wouldn't be aligning to four characters?

    I would have just stuck with %4 but apparently you can't have more than two == in a row with base64. Or something.

    Ah. I missed the whole set of requirements and focused just on the numbers. That's...special.

    It's not special, it's retarded! Fuck political correctness!


  • BINNED

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    Neither does what you wrote, that's why:

    is there a single situation where % 4 % 2 is different than just % 2?

    What he's saying is that % 4 % 2 doesn't make sense. It's literally the same as % 2. (Unless C# uses a very fucked up definition of % I'm not aware of, which I doubt).


  • Notification Spam Recipient

    @topspin said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    Neither does what you wrote, that's why:

    is there a single situation where % 4 % 2 is different than just % 2?

    What he's saying is that % 4 % 2 doesn't make sense. It's literally the same as % 2. (Unless C# uses a very fucked up definition of % I'm not aware of, which I doubt).

    Yes, I edited way before he commented that it also didn't work properly.


  • Java Dev

    @Tsaukpaetra said in WTF Bites:

    @Benjamin-Hall said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    And I'm guessing x % 3 (which would return exactly one of 0 1 2 wouldn't work because...

    Because then it wouldn't be aligning to four characters?

    I would have just stuck with %4 but apparently you can't have more than two == in a row with base64. Or something.

    You never need 3 characters of padding because you never end with a single base64 byte because a single base64 byte only contains 6 bits and isn't enough to make a payload bytes.

    The payload is grouped per 3 bytes. Then:

    • If the payload length %3 is 0, then the encoded length %4 is 0 and you don't have padding.
    • If the payload length %3 is 1, then the encoded length %4 is 2, with 4 junk bits in the last encoded character and 2 bytes of padding.
    • If the payload length %3 is 2, then the encoded length %4 is 3, with 2 junk bits in the last encoded character and 1 byte of padding.


  • @PleegWat said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @Benjamin-Hall said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    And I'm guessing x % 3 (which would return exactly one of 0 1 2 wouldn't work because...

    Because then it wouldn't be aligning to four characters?

    I would have just stuck with %4 but apparently you can't have more than two == in a row with base64. Or something.

    You never need 3 characters of padding because you never end with a single base64 byte because a single base64 byte only contains 6 bits and isn't enough to make a payload bytes.

    The payload is grouped per 3 bytes. Then:

    • If the payload length %3 is 0, then the encoded length %4 is 0 and you don't have padding.
    • If the payload length %3 is 1, then the encoded length %4 is 2, with 4 junk bits in the last encoded character and 2 bytes of padding.
    • If the payload length %3 is 2, then the encoded length %4 is 3, with 2 junk bits in the last encoded character and 1 byte of padding.

    sounds like the kind of situation where a string[4] would work much better, and have the added bonus that you could set the one that should never happen to null


  • Java Dev

    @ben_lubar said in WTF Bites:

    @PleegWat said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @Benjamin-Hall said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    And I'm guessing x % 3 (which would return exactly one of 0 1 2 wouldn't work because...

    Because then it wouldn't be aligning to four characters?

    I would have just stuck with %4 but apparently you can't have more than two == in a row with base64. Or something.

    You never need 3 characters of padding because you never end with a single base64 byte because a single base64 byte only contains 6 bits and isn't enough to make a payload bytes.

    The payload is grouped per 3 bytes. Then:

    • If the payload length %3 is 0, then the encoded length %4 is 0 and you don't have padding.
    • If the payload length %3 is 1, then the encoded length %4 is 2, with 4 junk bits in the last encoded character and 2 bytes of padding.
    • If the payload length %3 is 2, then the encoded length %4 is 3, with 2 junk bits in the last encoded character and 1 byte of padding.

    sounds like the kind of situation where a string[4] would work much better, and have the added bonus that you could set the one that should never happen to null

    I presume you're talking about encoding, which ends up looking kind of like this:

    int base64encode(byte * inbuf, size_t insz, char * outbuf, size_t outsz)
    {
        if( (insz + 2)/3*4 + 1 > outsz ) {
            trace( "output buffer is only %zu bytes, %zu bytes needed to encode %zu bytes\n",
                    outsz, (insz + 2)/3*4 + 1, insz );
            return -1;
        }
    
        while( insz > 0 ) {
            if( insz >= 3 ) {
                *outbuf[0] = enctab[ (inbuf[0] >> 2) & 0x3F ];
                *outbuf[1] = enctab[ (inbuf[0] << 4) & 0x30 | (inbuf[1] >> 4) & 0x0F ];
                *outbuf[2] = enctab[ (inbuf[1] << 2) & 0x3C | (inbuf[3] >> 6) & 0x03 ];
                *outbuf[3] = enctab[ (inbuf[2] >> 2) & 0x3F ];
            } else if( insz == 2 ) {
                *outbuf[0] = enctab[ (inbuf[0] >> 2) & 0x3F ];
                *outbuf[1] = enctab[ (inbuf[0] << 4) & 0x30 | (inbuf[1] >> 4) & 0x0F ];
                *outbuf[2] = enctab[ (inbuf[1] << 2) & 0x3C ];
                *outbuf[3] = '=';
            } else {
                *outbuf[0] = enctab[ (inbuf[0] >> 2) & 0x3F ];
                *outbuf[1] = enctab[ (inbuf[0] << 4) & 0x30 ];
                *outbuf[2] = '=';
                *outbuf[3] = '=';
            }
            inbuf  += 3; insz  -= 3;
            outbuf += 4; outsz -= 4;
        }
    
        *outbuf = '\0';
        return 0;
    }
    

    Linebreaks every 76 characters left as an exercise to the reader.



  • @PleegWat I'm talking about padding, which pretty much everyone who's replied to me seems to have forgotten somehow.

    In Go, you'd just use the version of the decoder that doesn't use padding.



  • @BrisingrAerowing said in WTF Bites:

    @hungrier Metroid Prime 2 is one of my favorite games.

    I've only played a bit of 2 but I really like the first one. Maybe some day I'll pick it back up


  • Notification Spam Recipient

    @ben_lubar said in WTF Bites:

    In Go,

    Nobody except you was talking about golang,

    @ben_lubar said in WTF Bites:

    which pretty much everyone who's replied to me seems to have forgotten somehow.

    Methinks they're beating bushes.


  • Java Dev

    @ben_lubar said in WTF Bites:

    @PleegWat I'm talking about padding, which pretty much everyone who's replied to me seems to have forgotten somehow.

    In Go, you'd just use the version of the decoder that doesn't use padding.

    If you're using a helper, you don't need to care about your own padding. Using a helper that requires padding when your input doesn't have any is :doing_it_wrong:.
    If you're doing it yourself, which padding you need to apply or expect follows from the way you're doing block parsing, based on the three possible block types, a state machine, or similar.
    In any case I don't see a lookup array for four types of parsing (one of which is invalid, and one empty) being useful. But that may just be me.



  • @PleegWat said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @Benjamin-Hall said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    @ben_lubar said in WTF Bites:

    @Tsaukpaetra said in WTF Bites:

    Status: This feels so wrong but it's the only way I've been able to get the fucking .Net Base64 decoder to accept my strings...

    string datastring = s[1];
    datastring += "==".Substring(0, datastring.Length % 4 % 2);
    datastring += "==".Substring(0, datastring.Length % 4);
    string result = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(datastring));
    

    I don't know wtf is going on but hey, it works?

    Edit: Wait, no it doesn't.

    For fuck's sake...

    Edit 2: This one works?

    Mind slowly exploding. Shirley there must be a better way to do this...

    is there a single situation where % 4 % 2 is different than just % 2?

    Yes. Apparently. In cases where you want 0, 1, or 2 (but not 3, heaven forbid!) characters to be added.

    x % 2 will never return 2

    Exactly. Apparently sometimes this is needed. Did you even read?

    And I'm guessing x % 3 (which would return exactly one of 0 1 2 wouldn't work because...

    Because then it wouldn't be aligning to four characters?

    I would have just stuck with %4 but apparently you can't have more than two == in a row with base64. Or something.

    You never need 3 characters of padding because you never end with a single base64 byte because a single base64 byte only contains 6 bits and isn't enough to make a payload bytes.

    The payload is grouped per 3 bytes. Then:

    • If the payload length %3 is 0, then the encoded length %4 is 0 and you don't have padding.
    • If the payload length %3 is 1, then the encoded length %4 is 2, with 4 junk bits in the last encoded character and 2 bytes of padding.
    • If the payload length %3 is 2, then the encoded length %4 is 3, with 2 junk bits in the last encoded character and 1 byte of padding.

    Visual aid:

    ee8f7217-0710-4c2a-8c29-8893f88d7c31-image.png


  • Grade A Premium Asshole

    @PleegWat said in WTF Bites:

    I presume you're talking about encoding, which ends up looking kind of like this:

    int base64encode(byte * inbuf, size_t insz, char * outbuf, size_t outsz)
    {
    

    Nit: inbuf should be a pointer to const byte.

        if( (insz + 2)/3*4 + 1 > outsz ) {
    

    Potential integer overflow in (insz + 2)/3*4 + 1.

            trace( "output buffer is only %zu bytes, %zu bytes needed to encode %zu bytes\n",
                    outsz, (insz + 2)/3*4 + 1, insz );
            return -1;
        }
    
        while( insz > 0 ) {
    

    Uh oh. Due to insz being an unsigned integer variable, this condition is equivalent to insz != 0.

            if( insz >= 3 ) {
                *outbuf[0] = enctab[ (inbuf[0] >> 2) & 0x3F ];
    

    Type error: *outbuf[0] should be outbuf[0].

            // ...
            inbuf  += 3; insz  -= 3;
    

    Bug: insz -= 3 can never go negative, only hueg. This will potentially loop forever (see "Uh oh" above).

            outbuf += 4; outsz -= 4;
    

    outsz is written to but never read from.


  • Java Dev

    @bugmenot said in WTF Bites:

    @PleegWat said in WTF Bites:

    I presume you're talking about encoding, which ends up looking kind of like this:

    int base64encode(byte * inbuf, size_t insz, char * outbuf, size_t outsz)
    {
    

    Nit: inbuf should be a pointer to const byte.

    Granted. Bad habit in my current codebase that's beyond ever fixing.

        if( (insz + 2)/3*4 + 1 > outsz ) {
    

    Potential integer overflow in (insz + 2)/3*4 + 1.

    If this is more than 2^60 my problems are larger than a bad range check here.

            trace( "output buffer is only %zu bytes, %zu bytes needed to encode %zu bytes\n",
                    outsz, (insz + 2)/3*4 + 1, insz );
            return -1;
        }
    
        while( insz > 0 ) {
    

    Uh oh. Due to insz being an unsigned integer variable, this condition is equivalent to insz != 0.

    Not generally a problem, but...

            if( insz >= 3 ) {
                *outbuf[0] = enctab[ (inbuf[0] >> 2) & 0x3F ];
    

    Type error: *outbuf[0] should be outbuf[0].

    Granted. I didn't run a compiler against this.

            // ...
            inbuf  += 3; insz  -= 3;
    

    Bug: insz -= 3 can never go negative, only hueg. This will potentially loop forever (see "Uh oh" above).

    That's a real one. I would probably have put some breaks in once I'd found this out.

            outbuf += 4; outsz -= 4;
    

    outsz is written to but never read from.

    Style mandate. If you've got a buffer pointer+size pair, don't ever update the pointer without also updating the size.



  • Non-technical WTF: Apparently, the only grass seed available on (Canadian) Amazon is either ridiculously expensive, or apparently so dangerous they can't even ship it

    10927033-d533-4db4-8f1c-433e3f6c3ec6-image.png

    e: Example of the first thing

    20e1a26d-a1b7-4d3f-946c-5bfe2694a4d3-image.png



  • @hungrier Considered invasive in your location, or something like that?



  • @HardwareGeek They don't react well to cold ☃



  • @HardwareGeek If so, it's too late because we have grass in Canada. Just not on my lawn



  • I guess I could just go down to Canadian Tire and get some, but by the time I wait out the lineup it'll be winter again.

    For comparison:

    c44bb6e1-a008-40d5-860f-eba242c18a68-image.png

    7f684481-1d6e-47eb-8d1d-056e91a16e52-image.png



  • @hungrier wait, a tire store has lawn products?

    :wat:


  • Banned

    @hungrier the product name looks like some joke I'm not getting.


  • Banned

    @Benjamin-Hall said in WTF Bites:

    @hungrier wait, a tire store has lawn products?

    :wat:

    Apparently.

    Screenshot_20200608_030833.jpg


  • Banned

    Inb4 jokes about outdoor living in Canada. ☃



  • @Benjamin-Hall said in WTF Bites:

    @hungrier wait, a tire store has lawn products?

    :wat:

    Canadian Tire has all kinds of stuff. I guess they started out with automotive and tires, and grew from there into pretty much a department store



  • @hungrier Canadians. Can't even name things right... 🏆



  • @hungrier said in WTF Bites:

    @HardwareGeek If so, it's too late because we have grass in Canada. Just not on my lawn

    I can't find any information online on what species of grass seed is included in Scotts Lawn Response 9-1-1, but for example some locations consider various bluegrasses invasive. (Paradoxically, Kentucky considers Kentucky bluegrass invasive.) Annual and perennial ryegrass, bermudagrass, Bahiagrass, and bentgrass are others that are widely used lawn grasses but considered invasive in some areas. Perhaps that seed mix contains something that is banned in yours.



  • @HardwareGeek I might be misremembering but I think Kentucky bluegrass is one of the common lawn grasses around here so it should be fine



  • @hungrier that's not grass seed, it's turf


Log in to reply