Bug #26978 s->z_err not assigned a value?
Submitted: 9 Mar 2007 0:33 Modified: 9 Apr 2008 15:54
Reporter: Chongfeng Hu Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Archive storage engine Severity:S3 (Non-critical)
Version:5.1.17-BK, 5.2.0 falcon-alpha OS:Any (any)
Assigned to: Sergey Vojtovich CPU Architecture:Any
Tags: z_err

[9 Mar 2007 0:33] Chongfeng Hu
Description:
I found that whenever there's an error in processing, azio_stream->z_err should always contain an error number. However, in file storage/archive/azio.c, function int get_byte(s)  azio_stream *s;, I saw the following piece of code:

    if (s->stream.avail_in == 0)
    { 
      s->z_eof = 1;
      /* if (ferror(s->file)) s->z_err = Z_ERRNO; */
      return EOF;
    }

Here, the assignment to z_err is commented out. Should it still be assigned an appropriate value?

How to repeat:
I found this spot with the help of a code-analysis tool.
[9 Mar 2007 10:47] Valeriy Kravchuk
Thank you for a problem report. Verified by code review also on 5.1.17-BK. We have:

/* ===========================================================================
  Read a byte from a azio_stream; update next_in and avail_in. Return EOF
  for end of file.
  IN assertion: the stream s has been sucessfully opened for reading.
*/
int get_byte(s)
  azio_stream *s;
{
  if (s->z_eof) return EOF;
  if (s->stream.avail_in == 0)
  {
    errno = 0;
    s->stream.avail_in = my_read(s->file, (byte *)s->inbuf, AZ_BUFSIZE, MYF(0));
    if (s->stream.avail_in == 0)
    {
      s->z_eof = 1;
      /* if (ferror(s->file)) s->z_err = Z_ERRNO; */
      return EOF;
    }
    s->stream.next_in = s->inbuf;
  }
  s->stream.avail_in--;
  return *(s->stream.next_in)++;
}

So, even if it is not a bug (EOF may be just returned in case of any problem intentionally), this comment should be removed as misleading.
[12 Dec 2007 13:16] 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/39774

ChangeSet@1.2638, 2007-12-12 17:16:59+04:00, svoj@mysql.com +1 -0
  BUG#26978 - s->z_err not assigned a value?
  
  azio didn't handle situation when my_read() returns error.
  
  Added handling of situation when my_read() returns error.
  
  No test case for this fix.
[27 Mar 2008 11:17] Bugs System
Pushed into 5.1.24-rc
[27 Mar 2008 17:49] Bugs System
Pushed into 6.0.5-alpha
[9 Apr 2008 10:01] Sergey Vojtovich
This is too low level change and it is very unlikely that somebody would experience this problem. Leaving the decision, whether to document this issue or not, to docs team with explanation below.

Memory corruption and/or server crash may occur when low-level I/O error occurs during opening an archive table.
[9 Apr 2008 15:54] Jon Stephens
Documented in the 5.1.24 and 6.0.5 changelogs as follows:

        Memory corruption, a crash of the MySQL server, or both, could take
        place if a low-level I/O error occurred while an ARCHIVE table was being
        opened.