You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Andrew Olson (Jira)" <ji...@apache.org> on 2021/02/01 22:58:00 UTC

[jira] [Commented] (AVRO-2944) DataFileReader has incorrect logic reading magic header

    [ https://issues.apache.org/jira/browse/AVRO-2944?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17276713#comment-17276713 ] 

Andrew Olson commented on AVRO-2944:
------------------------------------

[~mickjermsurawong-stripe] [~rskraba] It's not clear to me how this patch actually handles the case of the InputStream returning -1. Wouldn't the value of c in the loop just continue to decrease in that case (until it underflows anyway)?

Shouldn't it look something like this?

{noformat}
int c = 0;
while (c < magic.length) {
  int bytesRead = in.read(magic, c, magic.length - c);

  // break if EOF is reached
  if (bytesRead == -1)
    break;

  c += bytesRead;
}
{noformat}

> DataFileReader has incorrect logic reading magic header
> -------------------------------------------------------
>
>                 Key: AVRO-2944
>                 URL: https://issues.apache.org/jira/browse/AVRO-2944
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.9.2
>            Reporter: Mick Jermsurawong
>            Assignee: Mick Jermsurawong
>            Priority: Major
>             Fix For: 1.10.1
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> When creating reader using static method which includes checking for magic header, we currently read 4 bytes but the pointer is not correctly updated.
> [https://github.com/apache/avro/blob/328c539afc77da347ec52be1e112a6a7c371143b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java#L61-L62]
> When inputstream reads less byte than expected, this will get stuck in the loop until the end of file. Or if inputstream returns -1, for EOF like S3AInpustream, read hangs in this loop.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)