diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h
index c00048d1670da..7c2385be48b8a 100644
--- a/src/google/protobuf/parse_context.h
+++ b/src/google/protobuf/parse_context.h
@@ -236,7 +236,9 @@ class PROTOBUF_EXPORT EpsCopyInputStream {
if (aliasing_ == kOnPatch) aliasing_ = kNoDelta;
return flat.data();
} else {
- std::memcpy(buffer_, flat.data(), flat.size());
+ if (!flat.empty()) {
+ std::memcpy(buffer_, flat.data(), flat.size());
+ }
limit_ = 0;
limit_end_ = buffer_end_ = buffer_ + flat.size();
next_chunk_ = nullptr;