Bug #19285 NDBAPI blob access can corrupt tables if done wrong
Submitted: 23 Apr 2006 2:08 Modified: 19 Jun 2006 17:28
Reporter: Hartmut Holzgraefe Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:5.0, 5.1 OS:Linux (linux)
Assigned to: Pekka Nousiainen CPU Architecture:Any

[23 Apr 2006 2:08] Hartmut Holzgraefe
Description:
The NDBAPI NdbBlob documentation page says:

* readTuple with exclusive lock can also update existing value

i tried to modify a blob in a table created by mysqld using the NdbApi today,
i used NdbOperation->readTuple(LM_Exclusive) so i expected to be able
to modify the BLOB contents using NdbBlob->writeData() or NdbBlob->truncate().

These operations reported success (probably due to the "lock mode vs allowed 
operation is not checked" bug/limitation listed on the NdbBlog doc page), but after
a truncate i found that the next blob access using the ndbapi still returned the old
blob length (>1000bytes instead of the 100 i truncated to) and that only the first
256 bytes of data were still available, readData() returned random data for the
rest of it.

When trying to access the blob table using mysqld afterwards a
 
 SELECT id FROM table;

still worked fine but a

 SELECT id, blobfield FROM table;

returned an empty set instead, sometimes giving 4009 errors as
warnings, sometimes even without a warning.

The same operations worked fine when using updateTuple() instead of readTuple().

I assume this is a combination of the Bugs/Limitations:
 - lock mode upgrade should be handled automatically
 - lock mode vs allowed operation is not checked

but being able to severely damage blobs in a table without being given
any warning whatsoever is not acceptable IMHO (and even *with* warnings
it would still be a very bad thing)

How to repeat:
unpack the attached source archive,

  cd pk_lookup
  mysql -u ... test < dump.sql
  ./autogen.sh
  ./configure --with-mysql=/path/to/mysql_config
  make 
  ./pk_lookup # first call will read, then truncate a blob
  ./pk_lookup # 2nd call should show a 100byte blob now but doesn't
  mysql -u ... -e "SELECT id FROM session;" test # returns 1 row  
  mysql -u ... -e "SELECT id, data FROM session;" test # should also return 1 row but returns none
[23 Apr 2006 2:12] Hartmut Holzgraefe
test source and db dump

Attachment: pk_lookup.tar.gz (application/x-gunzip, text), 17.14 KiB.

[5 Jun 2006 9:27] Pekka Nousiainen
Possibly the comment  in NdbBlob.hpp is overly optimistic.
It should work though so it's worth to find out why not.

Low internal prio, this is not used by MySQL or known
API programs.
[14 Jun 2006 11:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/7627
[17 Jun 2006 11:00] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/7807
[17 Jun 2006 11:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/7810
[17 Jun 2006 18:27] Pekka Nousiainen
The patch is strictly for NDB API and basically fixes the sloppy
documentation in NdbBlob.hpp.

- documents what operations are allowed on blob  handles
- checks for not allowed operations (new error code 4275)
- automatic read lock upgrade of read committed to read shared

Read exclusive + blob update is NOT allowed.  The easy solution
would introduce overhead for non-updating case too.
[19 Jun 2006 17:28] Jon Stephens
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Updated 5.0.23/5.1.12 changelogs and NdbBlob section of NDBAPI Guide. Closed.