Skip to content

pubmatic: return error for banner with no sizes and no format - #4643

Open
Aditya-9-6 wants to merge 3 commits into
prebid:masterfrom
Aditya-9-6:fix/pubmatic-banner-no-sizes-java
Open

Aditya-9-6 wants to merge 3 commits into
prebid:masterfrom
Aditya-9-6:fix/pubmatic-banner-no-sizes-java

Conversation

@Aditya-9-6

Copy link
Copy Markdown

Summary

This is a Java port of the Go fix from prebid/prebid-server#5008, as requested in issue prebid/prebid-server#5002 (comment by @osulzhenko).

Problem

PubmaticBidder.assignSizesIfMissing() silently returned the banner unchanged when format was empty and no explicit W/H were set, forwarding a dimensionless banner to PubMatic — leading to invalid requests.

Go's equivalent (assignBannerSize) was already fixed to return a BadInput error in such cases. Java was missing the same guard.

What is different in Java vs Go

The call order in Java differs from Go:

  • fillBannerSizeFromFormat() (formerly assignSizesIfMissing) is called before enrichWithAdSlotParameters()
  • When adSlot contains @WxH (e.g. slot@300x250), enrichWithAdSlotParameters sets W/H on the imp builder after the format-fill step

So we cannot throw eagerly in fillBannerSizeFromFormat — a valid imp with empty format but adSlot-derived dimensions would be incorrectly rejected.

Fix

  • Renamed assignSizesIfMissing → fillBannerSizeFromFormat to clarify its single responsibility (copying dims from format[0] when W/H are absent)
  • Added a post-enrichment validation in modifyImp(): if the resulting banner still has no W/H after both steps, throw PreBidException("No sizes provided for Banner")

Tests added

  1. makeHttpRequestsShouldReturnErrorIfBannerHasNoSizesAndNoFormat — banner with empty format and adSlot without @ → BadInput error
  2. makeHttpRequestsShouldAllowBannerWithNoFormatWhenAdSlotProvidesSize — banner with empty format but adSlot = slot@300x250 → W=300, H=250 from adSlot, no error

Fixes #5002 (cross-repo issue from prebid/prebid-server#5002)

Port of Go fix from prebid-server#5008 (prebid/prebid-server#5008).

In Go, assignBannerSize() returns a BadInput error when banner.Format
is empty and no explicit W/H are present, preventing a panic.

The Java implementation had the same logical gap: assignSizesIfMissing()
silently returned the banner unchanged when format was empty, forwarding
a dimensionless banner to PubMatic.

This commit:
- Renames assignSizesIfMissing -> fillBannerSizeFromFormat to clarify its
  role (only copies dims from Format[0]; does not validate)
- Adds a post-enrichment check in modifyImp() that throws PreBidException
  when the resulting banner still has no W/H after both fillBannerSizeFromFormat
  and enrichWithAdSlotParameters have run
- This preserves the valid case where adSlot (e.g. slot@300x250) supplies
  dimensions even when format is empty

Closes #5002 (see also prebid/prebid-server#5002)
@osulzhenko
osulzhenko requested a review from CTMBNara September 30, 2026 07:35
@osulzhenko
osulzhenko removed the request for review from CTMBNara September 30, 2026 11:34
@osulzhenko osulzhenko added the do not merge Not the time for merging yet label Sep 30, 2026
Per OpenRTB 2.6 spec, banner sizes are optional for interstitial impressions
(imp.instl=1), as interstitials fill the full screen. The previous fix
incorrectly discarded these legitimate impressions.

Skip the no-sizes PreBidException when the imp has instl=1, even if both
W/H are absent and format is empty.
@aleksUIX

aleksUIX commented Oct 4, 2026

Copy link
Copy Markdown

The new check only rejects when both w and h are missing. With w=300, h=null, no format, and an adSlot without size, the banner still passes through. Could the check reject either missing dimension?

Update banner dimensions validation to check if either width or height
is missing ((w == null || h == null)), preventing banners with only one
dimension set from passing through.
@Aditya-9-6

Copy link
Copy Markdown
Author

Good catch! Updated the check to (resultBanner.getW() == null || resultBanner.getH() == null)\ so it rejects if either dimension is missing when no format/adSlot dimensions are available, and added a unit test for \w=300, h=null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Not the time for merging yet do not port

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants