[
https://issues.apache.org/jira/browse/KAFKA-20177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18058051#comment-18058051
]
Abdgali Yerkingaliyev edited comment on KAFKA-20177 at 2/12/26 7:53 AM:
------------------------------------------------------------------------
Created PR for this issue:
https://github.com/apache/kafka/pull/21463
Summary of changes:
- Hardened partition.metadata parsing in PartitionMetadataReadBuffer to avoid
NPE on malformed/truncated files.
- Added validation for expected keys and malformed UUID handling.
- Added tests for malformed/valid parsing cases and for PartitionMetadataFile
read error propagation.
Tests run:
./gradlew -q :storage:test --tests
org.apache.kafka.storage.internals.checkpoint.PartitionMetadataReadBufferTest
--tests org.apache.kafka.storage.internals.checkpoint.PartitionMetadataFileTest
was (Author: JIRAUSER312429):
Created PR for this issue:
https://github.com/apache/kafka/pull/<PR_NUMBER>
Summary of changes:
- Hardened partition.metadata parsing in PartitionMetadataReadBuffer to avoid
NPE on malformed/truncated files.
- Added validation for expected keys and malformed UUID handling.
- Added tests for malformed/valid parsing cases and for PartitionMetadataFile
read error propagation.
Tests run:
./gradlew -q :storage:test --tests
org.apache.kafka.storage.internals.checkpoint.PartitionMetadataReadBufferTest
--tests org.apache.kafka.storage.internals.checkpoint.PartitionMetadataFileTest
> Handle malformed partition.metadata without NullPointerException
> ----------------------------------------------------------------
>
> Key: KAFKA-20177
> URL: https://issues.apache.org/jira/browse/KAFKA-20177
> Project: Kafka
> Issue Type: Bug
> Components: core
> Affects Versions: 4.3.0
> Reporter: Abdgali Yerkingaliyev
> Priority: Minor
>
> h3. Problem
> `PartitionMetadataReadBuffer` can throw `NullPointerException` when
> `partition.metadata` is empty or truncated.
> h3. In
> {{{}org.apache.kafka.storage.internals.checkpoint.PartitionMetadataReadBuffer.java{}}},
> parsing uses {{split(line)}} even when {{{}line == null{}}}.
> This can bypass the expected malformed-file handling path and lead to less
> consistent error handling for partition metadata read failures.
>
> h3. Expected behavior
> Malformed {{partition.metadata}} should fail with a controlled
> {{IOException}} (malformed line / invalid topic id), not with
> {{{}NullPointerException{}}}.
> h3. Proposed fix
> * Make parsing null-safe in {{{}PartitionMetadataReadBuffer{}}}.
> * Validate key/value lines explicitly ({{{}version{}}}, {{{}topic_id{}}}).
> * Convert malformed UUID parsing into {{IOException}} via existing
> malformed-line path.
> h3. Tests
> * Add focused tests for: - empty file - missing {{topic_id}} line -
> malformed UUID - {{ZERO_UUID}} - valid metadata file
> * Add integration-style check that malformed file read is surfaced as
> {{KafkaStorageException}} by {{{}PartitionMetadataFile.read(){}}}.
> h3. Compatibility / Risk
> Low risk. Behavior is only changed for malformed input; valid files are
> unaffected.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)