Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
boo_radley
Dec 30, 2005

Politeness costs nothing

Volguus posted:

Yeah, me as well, based on the quoted javadoc though. os::random() .... wouldn't have imagined.

Christ alive! And as a default, too. :psyduck:

Adbot
ADBOT LOVES YOU

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

Makes sense. Actually hashing things is slow, and all you really need is an identifier that hopefully doesn't collide. Random also means that it's harder to find a way to rely on the particular implementation.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
There's a very specific reason to use randomness here. If you don't randomize hashes intended for O(1) lookup algorithms you open yourself up to DOS attacks whenever a malicious user is able to control the values that get hashed, for instance through a web server or a command line interface. If the exact hash algorithm is known ahead of time and you're able to pass a bunch of keys into a hash table, you can create lots of strings that collide, causing performance to degenerate drastically in some cases. You can effectively turn hash tables into linked lists.

This is an attack vector that's been discovered and rediscovered multiple times throughout the history of programming. I believe the Java implementation goes back to 2011, when a couple of guys demonstrated that you could bring lots of websites to their knees simply by visiting a URL with lots of query parameters.

This article is a good summary: https://medium.freecodecamp.org/hash-table-attack-8e4371fc5261

And a video from back then:

https://www.youtube.com/watch?v=R2Cq3CLI6H8

Edit: On reflection, I'm not sure if the os:random() call in the default implementation in Java is actually related to this vulnerability, since that should mostly be relevant for strings. It may just be there to dissuade people from relying on precise hash values.

LOOK I AM A TURTLE fucked around with this message at 14:30 on Apr 26, 2018

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



CPColin posted:

It's hilarious that HotSpot has a command-line argument for which hash code algorithm you want. It's sad that somebody somewhere has probably had to use it.

And you're sure nothing in your stack/environment sets it? How sure? :unsmigghh:

Soricidus
Oct 21, 2010
freedom-hating statist shill

LOOK I AM A TURTLE posted:

Edit: On reflection, I'm not sure if the os:random() call in the default implementation in Java is actually related to this vulnerability, since that should mostly be relevant for strings. It may just be there to dissuade people from relying on precise hash values.

It isn’t related. This vulnerability is fixed by modifying the hash table implementation, not by randomising hash codes - you need hash codes to be deterministic whenever equality is different from identity, and java specifies exactly what algorithms must be used to compute them for many types.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
It's related in the sense that you wouldn't want the hash codes of successively-allocated objects to exhibit obvious and deterministic patterns, as it is imaginable that an attacker could figure out that a particular request will get a particular server to allocate a number of identity-hashed objects and then insert them into a hash table.

Rubellavator
Aug 16, 2007

Haven't found the horror yet. But I'm looking into a very unperformant report that I was told I ruined by adding an outer join too. We use a custom query builder for most of our sql operations and maps via some annotations on a model object.

Query runs in 2 seconds. 20 minutes later it has mapped all the rows. Mapping a single row takes longer than the query.

Volguus
Mar 3, 2009

Rubellavator posted:

Haven't found the horror yet. But I'm looking into a very unperformant report that I was told I ruined by adding an outer join too. We use a custom query builder for most of our sql operations and maps via some annotations on a model object.

Query runs in 2 seconds. 20 minutes later it has mapped all the rows. Mapping a single row takes longer than the query.

Using a query builder is not necessarily a bad thing. Using a query builder because the users do not know SQL is. Teach those users SQL and ditch the query builder (it becomes useless at that point).

necrotic
Aug 2, 2005
I owe my brother big time for this!
Sounds like the mapper is the horror anyway if it takes that long to map a single record. I don't even know how you'd make it that slow, really curious what you find out.

Tarezax
Sep 12, 2009

MORT cancels dance: interrupted by MORT
found some code today that was probably written before Java String.split, which used String.indexOf to split on tab characters and deserialize a TSV

Soricidus
Oct 21, 2010
freedom-hating statist shill

Tarezax posted:

found some code today that was probably written before Java String.split, which used String.indexOf to split on tab characters and deserialize a TSV

inexcusable, considering that StringTokenizer has been there since jdk 1.0

Rubellavator
Aug 16, 2007

necrotic posted:

Sounds like the mapper is the horror anyway if it takes that long to map a single record. I don't even know how you'd make it that slow, really curious what you find out.

Turns out it has something to do with the derby jdbc driver. Its the actual resultset.next () call that is taking so long. My suspicion was the fetchsize but increasing that did nothing.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
Not a horror, but I've been writing some LDAP code for the first time in my life and I found this in one of the many, many, many (many!) specifications:
pre:
2.11.  drink

   The 'drink' (favoriteDrink) attribute specifies the favorite drinks
   of an object (or person), for instance, "cola" and "beer".

      ( 0.9.2342.19200300.100.1.5 NAME 'drink'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} )

   The DirectoryString (1.3.6.1.4.1.1466.115.121.1.15) syntax and the
   'caseIgnoreMatch' and 'caseIgnoreSubstringsMatch' rules are described
   in [RFC4517].
I'm the object with a favorite drink

e: I love that it's also case-insensitive and searchable

hackbunny fucked around with this message at 17:51 on May 3, 2018

bigmandan
Sep 11, 2001

lol internet
College Slice

hackbunny posted:

Not a horror, but I've been writing some LDAP code for the first time in my life and I found this in one of the many, many, many (many!) specifications:
pre:
2.11.  drink

   The 'drink' (favoriteDrink) attribute specifies the favorite drinks
   of an object (or person), for instance, "cola" and "beer".

      ( 0.9.2342.19200300.100.1.5 NAME 'drink'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} )

   The DirectoryString (1.3.6.1.4.1.1466.115.121.1.15) syntax and the
   'caseIgnoreMatch' and 'caseIgnoreSubstringsMatch' rules are described
   in [RFC4517].
I'm the object with a favorite drink

e: I love that it's also case-insensitive and searchable

If you need to plan a lunch meeting for a bunch of execs, might be useful :v:

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
I have this mental image of the X.500 guys raiding their secretaries' rolodexes for ideas on what fields they should include in the person class

itskage
Aug 26, 2003


https://www.bleepingcomputer.com/news/security/somebody-tried-to-hide-a-backdoor-in-a-popular-javascript-npm-package/

quote:

According to the npm team, the backdoor "allowed for an attacker to input arbitrary code into a running server and execute it."

The original backdoored module was imported in other packages

But things didn't end here. The "getcookies" library was new and not that popular, being included in very few projects.
The npm team says it discovered a nested dependency chain through which the "getcookies" package had indirectly made it into the structure of a much popular library called "Mailparser."

Linear Zoetrope
Nov 28, 2011

A hero must cook
Hey, guess what? Twitter accidentally had everyone's passwords in plaintext due to a bug.

(Bonus: right now on the website their settings page where you can change your password is broken and leads to an error. The app apparently works)

Linear Zoetrope fucked around with this message at 23:19 on May 3, 2018

CPColin
Sep 9, 2003

Big ol' smile.
code:
if (request.save()) {
   log.debug("Request saved")

   return request
} else {
   log.error("Error saving request: ${request?.errors}")

   return null
}

retun request
My favorite parts are the null-safe call in the else block, even though a non-null-safe call on the same object has already happened, and the unnecessary return statement after the else block that's misspelled anyway.

Rubellavator
Aug 16, 2007

Linear Zoetrope posted:

Hey, guess what? Twitter accidentally had everyone's passwords in plaintext due to a bug.

(Bonus: right now on the website their settings page where you can change your password is broken and leads to an error. The app apparently works)

I once turned on audits for a certain Oracle product and it logged all the user defined encrypted fields into a table in plaintext. The metadata lookup was case sensitive and bulk imported fields were in the wrong case, so it couldn't find the metadata and just spit it out in plaintext.

Rubellavator fucked around with this message at 00:18 on May 4, 2018

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Linear Zoetrope posted:

Hey, guess what? Twitter accidentally had everyone's passwords in plaintext due to a bug.

(Bonus: right now on the website their settings page where you can change your password is broken and leads to an error. The app apparently works)

drat.

Thank goodness I use randomly generated passwords. Time to rotate this one.

Volguus
Mar 3, 2009

Zaphod42 posted:

drat.

Thank goodness I use randomly generated passwords. Time to rotate this one.

thank goodness my twitter password is 1234. I never forget them. Now, if i'd only be able to remember the usernames ....

canis minor
May 4, 2011

CPColin posted:

code:
if (request.save()) {
   log.debug("Request saved")

   return request
} else {
   log.error("Error saving request: ${request?.errors}")

   return null
}

retun request
My favorite parts are the null-safe call in the else block, even though a non-null-safe call on the same object has already happened, and the unnecessary return statement after the else block that's misspelled anyway.

This gives me recalls to the codebase I'm currently going through. Additionally - not much was ever deleted

Steve French
Sep 8, 2003

Here's a fun one. You execute the following query (nevermind why):

code:
update foo set bar_id = 0 where bar_id = ?;
It fails, because the query violated the unique constraint on the primary key. However, bar_id is not in the primary key, nor is it in any other unique index.

Can anyone guess why that happened? It's lovely.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
There's an update trigger on the table that tries to set the primary key equal to bar_id?

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
So

https://www.bleepingcomputer.com/news/microsoft/microsoft-adds-support-for-javascript-functions-in-excel/

of course

https://www.bleepingcomputer.com/news/security/poc-developed-for-coinhive-mining-in-excel-using-custom-javascript-functions/

Steve French
Sep 8, 2003

TooMuchAbstraction posted:

There's an update trigger on the table that tries to set the primary key equal to bar_id?

Nope, it actually has almost nothing to do with the bar_id column itself.

b0lt
Apr 29, 2005

Steve French posted:

Here's a fun one. You execute the following query (nevermind why):

code:
update foo set bar_id = 0 where bar_id = ?;
It fails, because the query violated the unique constraint on the primary key. However, bar_id is not in the primary key, nor is it in any other unique index.

Can anyone guess why that happened? It's lovely.

It touched a row that's already violating the unique constraint on the primary key?

Steve French
Sep 8, 2003

b0lt posted:

It touched a row that's already violating the unique constraint on the primary key?

Oooh, that'd be a good one.

The answer:

The table had an auto increment id column. The primary key was _not_ this id column, but instead a composite of the id column and the created_at column.

The created_at column was configured with "on update CURRENT_TIMESTAMP".

For any given bar_id, it was likely for there to be multiple rows with the same id, but different timestamps.

Volguus
Mar 3, 2009
If it's autoincremented, how can it be the same number in multiple rows?

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Volguus posted:

If it's autoincremented, how can it be the same number in multiple rows?

You can still assign an explicit value on creation or modify it on update.

Volguus
Mar 3, 2009

DaTroof posted:

You can still assign an explicit value on creation or modify it on update.

But why would ... oh, I see. Yup, they deserve it. Whatever happens, they completely deserve it.

Nth Doctor
Sep 7, 2010

Darkrai used Dream Eater!
It's super effective!


Sacrifice the original schema's designer to the gods of normalization.

Volguus
Mar 3, 2009

Nth Doctor posted:

Sacrifice the original schema's designer to the gods of normalization.

The schema is stupid, but not as stupid as developers updating/assigning an autoincrementing column. The current schema would at most have a performance and database size impact. Probably negligible on both sides. Overriding the autoincrement in any way makes it completely useless.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Volguus posted:

The schema is stupid, but not as stupid as developers updating/assigning an autoincrementing column. The current schema would at most have a performance and database size impact. Probably negligible on both sides. Overriding the autoincrement in any way makes it completely useless.

"Then we can just make up our own nice, readable numeric IDs without having to query the database to see what it came up with" - :downswords:

Steve French
Sep 8, 2003

Volguus posted:

The schema is stupid, but not as stupid as developers updating/assigning an autoincrementing column. The current schema would at most have a performance and database size impact. Probably negligible on both sides. Overriding the autoincrement in any way makes it completely useless.

It appears that in practice, the autoincrement ID is not used at all, and the ID is always set on insert (this appears to be some sort of annotation table for something else where these IDs are predetermined). So while setting an autoincrement ID is stupid, it's more that the column is autoincrement when it shouldn't be.

What bothers me here is having a composite primary key where part of the key is automatically updated whenever the row is modified.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


In very early versions of our software decades ago, we only had one, global sequence that each table pulled from to populate its own sequence column. This was back when the insert time was also set to be a unique constraint. They did a lot of terrible things to get a working prototype to take out for bids.

Volguus
Mar 3, 2009

duz posted:

In very early versions of our software decades ago, we only had one, global sequence that each table pulled from to populate its own sequence column. This was back when the insert time was also set to be a unique constraint. They did a lot of terrible things to get a working prototype to take out for bids.

I have seen that done and I think that's perfectly fine. Especially when using an ORM that is able to prefetch a bunch of numbers and caching them. Nothing wrong with a sequence per table either.

ChickenWing
Jul 22, 2010

:v:

Steve French posted:

setting an autoincrement ID is stupid

Do you mean manually updating an autoincremented ID column, or are you saying that autoincremented UIDs are stupid (which I would need a lot more explanation on)

Steve French
Sep 8, 2003

ChickenWing posted:

Do you mean manually updating an autoincremented ID column, or are you saying that autoincremented UIDs are stupid (which I would need a lot more explanation on)

I mean explicitly setting the value of an autoincrement ID column. Though there _are_ ways that leaning too heavily on autoincremented UIDs can be bad, particularly exposing them pubicly, that's not what I meant.

Adbot
ADBOT LOVES YOU

FlapYoJacks
Feb 12, 2009
programmers who refuse to use IDE's are the absolute worst.

Every, single, loving time I open up code from a programmer that refuses to use a IDE, it's just a sea of red and yellow bullshit.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply